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.
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
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.
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
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').
You can try adding responseType as arraybuffer
axios.get(
fileUrl,
{headers:{'X-API-TOKEN':xxxxx}, responseType: 'arraybuffer'}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With