I have a binary zip file coming in as the response of an api call. I want to download that zip file directly using Javacript/React. How can I achieve this?
Asked
Active
Viewed 50 times
-1
-
FYI, I am getting a binary file as the response type from the api I am hitting. I need a way to download this binary file into my local file system – Mohit Kamal Apr 28 '23 at 10:05
-
Does this answer your question? [Handle file download from ajax post](https://stackoverflow.com/questions/16086162/handle-file-download-from-ajax-post) – Thomas Sablik Apr 28 '23 at 10:50
1 Answers
0
Read this FileReader and try this function:
function readFile(binaryFile) {
let reader = new FileReader();
reader.readAsArrayBuffer(binaryFile);
// in success case, do something with result
reader.onload = function() {
console.log(reader.result);
};
// in error case, do something with result
reader.onerror = function() {
console.log(reader.error);
};
}
best regards!

Yuri
- 34
- 7