我正在尝试将图像上传到azure存储器,如下所示:
var xhr = new XMLHttpRequest();
xhr.open("GET", blobUrl);
xhr.responseType = "text";//force the HTTP response, response-type header to be blob
xhr.onload = function () {
blobService.createBlockBlobFromText('taskcontainer', 'myblob', xhr.responseText, {contentSettings: {contentType: "image/bmp"}}, (error, result, response)=>{
})
}
xhr.send();
如果我上传一些像文本文件一样简单的'abc'它上传很好,但是如果我尝试上传类似图像的内容似乎已损坏,则差异显示文件上传到azure(左)之后和上传之前:https://user-images.githubusercontent.com/2121021/35678518-cb006af4-07a7-11e8-963d-2bb8b45aba26.png
我不确定究竟发生了什么,并且一直试图解决这个问题......
1 回答
那么,当您通过
XMLHttpRequest
对象接收二进制数据时,需要将responseType设置为arraybuffer
.