3

I have a JavaScript program that takes an uploaded zip file, unzips it using js-unzip, and then when it finds an unzipped PNG file, it takes the raw data from it.

images = [];
var files = evt.dataTransfer.files;
var data = files[0];
var reader = new FileReader();
reader.readAsDataURL(data);
reader.onload = function(thisFile){
    var zipFile = thisFile.target.result;
    var unzipper = new JSUnzip(window.atob(zipFile));
    unzipper.readEntries();
    var files = unzipper.entries;
    for(var i in files){
        var data = files[i].data;
        images[images.length] = new Image();
        images[images.length].src = 'data:image/png;base64,' + data;
    }
    context.drawImage(images[0], 0, 0);
}

It returns the error "GET data:image/png;base64,b``%C3%A0%C...". How can I process the image so that it draws it correctly?

Asraelite
  • 288
  • 4
  • 12
  • And where is the question? – ComFreek Sep 15 '13 at 10:10
  • How can I convert the data that the unzipper gives me of the PNG image, into printable raw image data that does not return an error? – Asraelite Sep 15 '13 at 10:16
  • 1
    Your RAW data is not BASE64 encoded... you still need to do that. This link might help you: http://stackoverflow.com/questions/246801/how-can-you-encode-a-string-to-base64-in-javascript/247261#247261 – jsmorph Sep 15 '13 at 10:43
  • If I try to encode the raw data of a png file using btoa I get this error : "InvalidCharacterError: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range." – kris Jun 30 '16 at 04:30

0 Answers0