我有一个PHP脚本,可以将PNG图像编码为Base64字符串.
我想用JavaScript做同样的事情.我知道如何打开文件,但我不知道如何进行编码.我不习惯使用二进制数据.
嗨,我想知道是否还有在AJAX中流式传输二进制响应?这将是一个终极解决方案,否则我需要将二进制映像实现为文件,然后使用不同的URL将该文件流式传输给用户.
new Ajax.Request('/viewImage?id=123', {
// request returns a binary image inputstream
onSuccess: function(transport) {
// text example
// alert(transport.responseText)
// QUESTION: is there a streaming binary response?
$('imgElem').src = transport.responseBinary;
},
onFailure: function(transport) {
// handle failure
}
});
Run Code Online (Sandbox Code Playgroud)