Dexter
Dexter

Reputation: 528

Unable to convert the base64 data to file using jszip in javascript

i have a base64 data coming via api and it is a tar file and i am trying to download using jszip but i am getting error

Uncaught (in promise) Error: Can't read the data of <base64 code>

below is my code

let bs = <somebase64code>
     let zip = new JSZip();


     zip.file(bs,{base64:true})

    zip.generateAsync({ type: "blob" }).then(function (content) {
      saveAs(content, "example");
    });

enter image description here

as the base64 code is large i havent attached it

Upvotes: 1

Views: 1083

Answers (1)

Endless
Endless

Reputation: 37806

jszip don't deal with tar files
tar and zip are not the same format
You need to use some other lib or use zip instead in the api

Also don't use base64, it will be ~3x ~33% larger in size.

Upvotes: 1

Related Questions