'Streaming zip to browser doesn't work, but works in Postman

I'm using the following package to download a ZIP file directly in the browser. For that I'm using following code in the frontend:

      await this.$axios
        .get(
          `/inspections/defects/download/${this.$route.params.uuid}`, {
              responseType: 'arraybuffer' // This is the problem
          }
        )
        .then((response) => {
          const url = window.URL.createObjectURL(
            new Blob([response.data], { type: 'application/octet-stream' })
          );
          const link = document.createElement('a');
          link.href = url;
          link.setAttribute('download', 'file.zip');
          document.body.appendChild(link);
          link.click();
        });

And from the backend I just directly use

app.get('/download/:uuid', (req, res) => {
  // get filename from db, but it's 99,9% the same as the example provided in the readme of the npm package.

  s3Zip
    .archive({ region: region, bucket: bucket }, '', 'abc.jpg')
    .pipe(res)
})

When I try to "send & download" via postman, it works perfectly, it downloads a zip with the image in it for around 5MB which is correct.

Now when I try to download it via the axios code, I get either

error 1

Or

error 2

After some research I always come to the same solution and that is to set the responseType and it seems to work for everyone. However, if I try to do that I get the following console errors, and I can't find any related issues when I google it:

console error

I've also tried with different content types, but can't seem to get my head around it. Especially because it works in Postman.

Related issue, but that was fixed by using arraybuffer: https://github.com/orangewise/s3-zip/issues/45



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source