node.jszipaxios

Unable to download ZIP file using Axios


This is the code I use:

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

The response data received is in binary, which I am converting to Base64 and saving in a file. After saving the ZIP file. If I try to open the file, it says invalid ZIP error.


Solution

  • You can try adding responseType as arraybuffer

    axios.get(
       fileUrl,
       {headers:{'X-API-TOKEN':xxxxx}, responseType: 'arraybuffer'}
    );