感谢@xchg.ca 的回答,我能够通过 jquery ajax 调用来做到这一点:
$.ajax({
type: "GET",
url: "imageURL",
beforeSend: function (xhr) {
xhr.overrideMimeType('text/plain; charset=x-user-defined');
},
success: function (result, textStatus, jqXHR) {
if(result.length < 1){
alert("The thumbnail doesn't exist");
$("#thumbnail").attr("src", "data:image/png;base64,");
return
}
var binary = "";
var responseText = jqXHR.responseText;
var responseTextLen = responseText.length;
for ( i = 0; i < responseTextLen; i++ ) {
binary += String.fromCharCode(responseText.charCodeAt(i) & 255)
}
$("#thumbnail").attr("src", "data:image/png;base64,"+btoa(binary));
},
error: function(xhr, textStatus, errorThrown){
alert("Error in getting document "+textStatus);
}
});