如何从 api 响应 async 和 deepai 中保存图像

我正在使用深度 AI API 将图像制作成卡通

await deepai.renderResultIntoElement(result,document.getElementById('RES'));
})();

如何保存该文件并将其显示在 RES div 中? 即使有更新,它也能很好地呈现!

更新:

await deepai.renderResultIntoElement(result,document.getElementById('RES'));

let e=await fetch(result,{
    method: 'GET',headers: {
      'Content-Type': 'image',},});

let blob=await e.blob();

let url=window.URL.createObjectURL(blob);
let a=document.createElement('a');
a.href=url;
a.download='cartoon.jpeg'; //here goes file name
document.body.appendChild(a);
a.click();
sleep(100);
a.remove();

})()

我也试过 let Blob=await response.blob(); 没有用,只是停止了渲染!

它几乎就在那里,它试图下载到一个文件,但它在打开时说格式不正确。有什么想法吗?

zhi_huiyudi 回答:如何从 api 响应 async 和 deepai 中保存图像

我设法通过从 callStandardApi 方法的结果向 url 发送 GET 请求来获取输出文件。
从中我得到了图像响应。
然后我使用 this 解决方案将其下载为带有硬编码名称的文件。

let e = await fetch(result.output_url,{
    method: 'GET',headers: {
      'Content-Type': 'image/jpeg',},});

let blob = await e.blob();

let url = window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = 'filename.jpeg'; //here goes file name
document.body.appendChild(a);
a.click();
a.remove();
本文链接:https://www.f2er.com/822.html

大家都在问