• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

21
Views
downloading application/zip file with javascript (with file-saver)

I am trying to download a zipfile that my webapp receives my backend in javascript. I am using the file-saver library, just because I use it in another part of the app, but I would also be ok, doing it with vanilla js (creating a blob, attaching it to hidden a element...). I tried out all I could find on the web about it, but it still doesn't work. The file is downloaded, but it cannot be opened, my archive manager just says there is an error... However, I know that the file coming from the server is ok. When test the endpoint of the api, that delivers the file, in swagger I can download and open the file normally.

if (response.headers["content-type"] === "application/zip") {
  const filename = response.headers['Content-Disposition'].match(/filename="(.+)"/)[1]
  FileSaver.saveAs(new Blob([response.data], {type: "application/zip"}), filename)
}

If anyone has any tip, on how I could go about debugging this, I would be very thankful :)

20 days ago ·

Santiago Gelvez

Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.