Home  >  Q&A  >  body text

Download the ZIP file in response to the api call

I have a binary zip file as response from an api call. I want to download the zip file directly using Javascript/React. How can I achieve this goal?

P粉034571623P粉034571623171 days ago317

reply all(1)I'll reply

  • P粉438918323

    P粉4389183232024-04-03 10:37:23

    Read this FileReader and try this function: < /p>

    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);
      };
    
    }

    with best regards!

    reply
    0
  • Cancelreply