Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to download zip file using axios

Tags:

node.js

zip

axios

This is the code I use:

axios.get(fileUrl, {headers:{'X-API-TOKEN':xxxxxx})

Response data received is in binary, Which I am converting to base64 and saving in file. After saving zip file. If I try to open the file, it says invalid zip error.

like image 544
sunil ts Avatar asked Nov 08 '17 07:11

sunil ts


People also ask

How to enable filedownload in Axios?

1. Configure your server to permit the browser to see required HTTP headers 2. Implement the server-side service, and making it advertise the correct file type for the downloaded file. 3. Implementing an Axios handler to trigger a FileDownload dialog within the browser

How to download PDF file using Axios in Vue JS?

var fileURL = window.URL.createObjectURL (new Blob ( [response.data])); In this step, visit /src/ directory and App.vue file. And then add the following code into it: Download file using axios in vue js. In this tutorial, you have learned how to download pdf file or zip file using vue js axios. My name is Devendra Dode.

How to get the URL of an Axios request?

In axios response object, inside request there is a field named As responseURL, maybe this is the URL that you want. – Hardik Modha Jan 31 '17 at 7:52

How does Axios work with @get?

The service responds to @GET (i.e. HTTP GET), so the Axios call must be 'axios.get(...)'. The document is transmitted as a stream of bytes, so you must tell Axios to treat the response as an HTML5 Blob. (I.e. responseType: 'blob').


1 Answers

You can try adding responseType as arraybuffer

axios.get(
   fileUrl,
   {headers:{'X-API-TOKEN':xxxxx}, responseType: 'arraybuffer'}
);
like image 123
Pram Avatar answered Oct 05 '22 20:10

Pram