1

I have an api which sends a zip file as a byte array (not the byte arrays of the individual files, but the zipped file on the whole). When I trigger the api in postman, i get random characters (as shown below).

When I download this response (as option in postman: send to a file and download) in a zip file, I am able to unzip it and extract the actual files. My goal is to achieve the same thing in angular and typescript.

I have tried to convert the response to a blob and download it, as suggested in multiple places online, including this question. So I did something like

const blob = new Blob([response], { type: 'application/zip' });
const url = window.URL.createObjectURL(blob);
window.open(url);

But the resultant zip file I download says 'unable to open: empty archive'. I am not sure what I am missing here. I tried converting the response to arrayBuffer (using this) first before applying the steps as well, as that was suggested in another place online. But that hasn't been of use either. Can someone please help me understand what I'm doing wrong. Thanks

I am calling the API in a js file:

function downloadAzureRT(params) {
      return $http({
        method: 'GET',
        url: API.public('protectionSources/downloadArtFile'),
        params: params || {},
      }).then(function downloadAwsARTResp(resp){
        return resp.data || {};
      });
    }

And then calling this function in a ts file.

downloadART() {
    this.ajsPubSourceService.downloadAzureRT({
      filePath: ART_FILE_PATH,
      fileName: ART_FILE_NAME,
    })
    .then((response) => {
        const blob = new Blob([response], { type: 'application/zip' });
        const url = window.URL.createObjectURL(blob);
        window.open(url);   
    }

0 Answers0