0

I'm getting binary file from a remote server, but I am unable to correctly store it locally using the file system. When I try to open the saved file, it shows as incorrect format etc and doesn't open the file. However, If I download the file directly from the site, it works fine. Need help on this. Thanks!

const fileData = await axios({ //this returns binary data.
    method: "get",
    url: instanceURL,
    headers: {
      "Authorization": "Bearer " + token,
    },
  });
  fs.writeFileSync(storePath, Buffer.from(fileData.data, "binary"));
Sam
  • 1,311
  • 2
  • 23
  • 47
  • Does this answer your question? [Download binary file with Axios](https://stackoverflow.com/questions/49040247/download-binary-file-with-axios) – eol Oct 18 '21 at 11:34
  • I tried `fs.writeFileSync(storePath, new Blob([fileData.data]));` but that's giving `Blob not defined` error – Sam Oct 18 '21 at 11:41
  • I ended up using the `fs.createWriteStream` to write the data. – Sam Oct 18 '21 at 11:54

0 Answers0