Image ReactJS:无法从REST API响应在UI中呈现图像

Image ReactJS:无法从REST API响应在UI中呈现图像,image,rest,reactjs,blob,Image,Rest,Reactjs,Blob,我已经构建了一个RESTAPI,它返回一个图像,我正在通过PostMan代理成功地获得它的响应。 在我的React代码中,我有: return fetch(url, sInit) .then((response) => { let blb = new Blob([response.body], { type: 'image/jpeg' }); let fileUrl = (window.URL || window.webkitURL).createObjectURL(b

我已经构建了一个RESTAPI,它返回一个图像,我正在通过PostMan代理成功地获得它的响应。 在我的React代码中,我有:

return fetch(url, sInit)
  .then((response) => {
    let blb = new Blob([response.body], { type: 'image/jpeg' });
    let fileUrl = (window.URL || window.webkitURL).createObjectURL(blb);
    window.open(fileUrl);
  })

生成的blob url没有图像。我缺少什么?

您可能希望通过
fetch使用内置方法:

fetch(
'https://images.unsplash.com/35/SRkdurVYQFSFkMyHVwSu_spinnenweb-9536.jpg?dpr=2&auto=compress,format&fit=crop&w=376&h=251&q=80&cs=tinysrgb&crop=
)
.then(res=>res.blob())
.然后(blob=>{
让fileUrl=(window.URL | | window.webkitURL).createObjectURL(blob);
const img=document.createElement('img');
img.src=文件URL;
document.querySelector('body').appendChild(img);

});你的答案很有帮助,但这在IE 8到11中不起作用。你是否包括了一个
fetch
由这些浏览器提供。请查看文档,IE10及以上版本支持
fetch
,但任何版本的Internet Explorer都不支持
blob()