adrianhajdin / project_ai_mern_image_generation

Build and Deploy a Full Stack MERN AI Image Generation App MidJourney & DALL E Clone
https://jsmastery.pro
1.11k stars 308 forks source link

File Saver npm Package not working after hosting #2

Open yashnarkhedkar opened 1 year ago

yashnarkhedkar commented 1 year ago

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

tynoschuck commented 1 year ago

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

ItsAnkitPatel commented 7 months ago

@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.