0

Im using deep AI API to make an image a cartoon

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

How can I save that file as well as it be displayed in a RES div? it renderes fine even with updates!

UPDATE:

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();

})()

I also tried let Blob=await response.blob(); that didnt work it just stopped it rendering!

Its nearly there its trying to download to a file but it is saying not correct format upon opening. any ideas?

1 Answers1

0

I managed to get output file by sending GET request to url from result of callStandardApi method.
From that I get image response.
Then I download it as a file with hard coded name using this solution.

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();
30james00
  • 51
  • 7
  • Thanks for reply, can i see the rest of it as im not using a get method im using blob from a ai i dont know how to send a file to that with a get method if you do please share the whole code on pastebin and share link :) – uk_user2014 Aug 01 '21 at 22:10
  • Iv updated the question as its sortof getting there maybe I hope. please check it out and tell me why it isnt quite working? I need to do the opposite to make a blob from something, i need to make a blob into a file that can be downloaded. – uk_user2014 Aug 01 '21 at 22:19
  • I tried saveAs(response, "image/jpeg", "image.jpeg"); And it didnt work any ideas? – uk_user2014 Aug 01 '21 at 22:46
  • It renders no problem it just dont save as a file ready for download or maybe even make it dl to client side without needing to dl first but i tried that and that idea failed. what did i do wrong in my js any ideas please? – uk_user2014 Aug 01 '21 at 22:58
  • Check for updated code as it not visable but comments should still work wele fix it from comments https://pastebin.com/ZU36uFbV – uk_user2014 Aug 01 '21 at 23:02
  • You are trying to use blob() method on response. Isn't that impossible? – 30james00 Aug 02 '21 at 07:39
  • its only viewable for me, how annoying i need help with this and should be able to update as and when needed! let Blob=await response.blob(); didnt work it stopped it working at all! – uk_user2014 Aug 02 '21 at 10:15