image

Procedure to send an image (download) via a node API, do I create read stream and pipe it to the front and if yes what gets sent from that binary, base64 string, array buffers?
4 Replies
ErickO
ErickO2y ago
are you using express? they got a helper for that
ErickO
ErickO2y ago
and in the front-end you do this annoying thing
const downloadBtn = document.getElementById("download-btn");
downloadBtn.addEventListener("click", async () => {
const image = await fetch("http://api.poop.com/download-image");
const imageBlog = await image.blob();
const imageURL = URL.createObjectURL(imageBlog);
const link = document.createElement("a");
link.href = imageURL;
link.download = "someimage";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
const downloadBtn = document.getElementById("download-btn");
downloadBtn.addEventListener("click", async () => {
const image = await fetch("http://api.poop.com/download-image");
const imageBlog = await image.blob();
const imageURL = URL.createObjectURL(imageBlog);
const link = document.createElement("a");
link.href = imageURL;
link.download = "someimage";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
Electronic
Electronic2y ago
Thanks
Want results from more Discord servers?
Add your server