project_ai_mern_image_generation icon indicating copy to clipboard operation
project_ai_mern_image_generation copied to clipboard

File Saver npm Package not working after hosting

Open yashnarkhedkar opened this issue 2 years ago • 2 comments

Hi there, When I run my app locally file saver working normally it download image to download folder. but I hosted website using netlify then when I click download button image opening in new tab what should I do?? please help Hosted website My Repo

yashnarkhedkar avatar Jan 21 '23 09:01 yashnarkhedkar

same problem for me. Not a big issue, but I'm curious how to fix it

tynoschuck avatar Jan 25 '23 10:01 tynoschuck

@yashnarkhedkar @tynoschuck

Inside utils/index.js update the downloadImage function

export async function downloadImage(_id, photo) {
  const securePhotoUrl = photo.replace('http://', 'https://');
  const imageBlob = await fetch(securePhotoUrl)
    .then((response) => response.arrayBuffer())
    .then((buffer) => new Blob([buffer], { type: "image/jpg" }));
  const url = URL.createObjectURL(imageBlob)
  FileSaver.saveAs(url, `download-${_id}.jpg`);
}

This worked for me.

ItsAnkitPatel avatar Mar 26 '24 06:03 ItsAnkitPatel