rndme / download

file downloading using client-side javascript
MIT License
2.28k stars 417 forks source link

How to send generated image to server without downloading it in react js? #114

Closed ali-mozaffari closed 1 year ago

ali-mozaffari commented 1 year ago

here in the wrote the below code for this purpose, but here it download the image and I want to send it to the server?

export const createPDF = async farmId => { const canvas = await html2canvas(document.getElementById('utmPagePdf')); const dataURL = canvas.toDataURL('image/png'); downloadjs(dataURL, 'download.png', 'image/png');

const data = new FormData(); data.append('farm_guid', farmId); data.append('file', '???');

AddUtmReport(data); };

Please guide me to solve this issue.

lemanschik commented 1 year ago

Note for you additional you can fetch('data:image/png..................')

then use what you read in the link posted below next to see.

cheers

see: https://github.com/rndme/download/pull/117/files

Closed by:

rndme commented 1 year ago

You can use canvas.toBlob() instead of dataURL, then you can use the Blob as a File. This means you won't really need download.js to append the file to your FormData.