my zip file is getting corrupt when its download

Viewed 52

i am trying to download zip which contain multiple files now i am able to download zip but files inside get's corrupt enter code here

downloadListConfig = () => {
    const { selectedList } = this.state;
    const list_ids = [];
    selectedList.forEach(list => {
      list_ids.push(list.id);
    });
    this.downloadListFile(list_ids);
  };
  // 1
  downloadListFile = list_ids => {
    downloadListConfig({ list_ids })
      .then(response => {
        const { body, headers } = response;
        let fileName = headers['content-disposition'].split('filename=')[1].split(';')[0];
        let data;
        if (headers['content-type'] === 'application/json') {
          data = new Blob([JSON.stringify(body)], { type: 'text/json' });
        } else {
          data = new Blob([body], { type: 'octet/stream' });
          // data = new Blob([body], {type})
        }
        const jsonURL = window.URL.createObjectURL(data);
        const tempLink = document.createElement('a');
        tempLink.href = jsonURL;
        tempLink.setAttribute('download', `${fileName}`);
        tempLink.click();
      })
      .catch(err => {
        console.log(err);
      });
  };
1 Answers

Application typ header should be application/zip

Related