简体   繁体   中英

Image Data to Blob from XMLHttpRequest

I am making an XMLHttpRequest :

request = new XMLHttpRequest();
request.open('GET', modifiedImageUrl, true);
request.onreadystatechange = ->
    if request.readyState == 4
        if request.status == 200
            blob = new Blob([request.response], { type: 'image/jpeg' })
request.send(null);

(Please excuse my coffeescript). I would like to create a Blob from the retrieved image, but am not getting any data in my blob besides the size and type:

Blob
    size: 88804
    type: "image/jpeg"
    > __proto__: Object

Looking at request.response :

响应(显示为文本的数据截图)

What is this format? How can I go about converting this to a Blob that has more information than just the size?

The blob has the data in it, you just can't view it like that.
Also if you didn't set your response type to arraybuffer(or blob) you image data is going to get corrupted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM