13

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.

Nikolaj Dam Larsen
  • 5,455
  • 4
  • 32
  • 45
sunil ts
  • 245
  • 1
  • 4
  • 12
  • Can you download the zip via the browser and see if the same error occurs? – Brett DeWoody Nov 08 '17 at 22:00
  • I tried it in postman. it is working fine in postman. – sunil ts Nov 10 '17 at 09:30
  • 1
    One trick I've used is to get the request working in Postman (which you've done), then click the 'Code' button in the mid-right corner of Postman, which will generate a code snippet to perform the current request in various languages - including Node. There isn't an Axios-specific option, but there are several Node options which will give you some into on the correct configuration. – Brett DeWoody Nov 10 '17 at 10:43

1 Answers1

41

You can try adding responseType as arraybuffer

axios.get(
   fileUrl,
   {headers:{'X-API-TOKEN':xxxxx}, responseType: 'arraybuffer'}
);
Pram
  • 2,383
  • 2
  • 19
  • 21