2

After the user uploads a zipped file, i want to remove the images folder from it before sending it over the network. I am using kendo for uploading, and the existing functionality works fine. I just want to add on the removing images part. This is what i have so far:

   function onSelect(e) {
        var file = e.files[0];
        if (endsWith(file.name, '.eds')) {
            var contents = e.target.result;
            var jszip = new JSZip(contents);
            jszip.remove("apldbio/sds/images_barcode");
            fileToSend = jszip.generate({type: "base64", compression: "DEFLATE"});
        }
        e.files[0] = fileToSend;
        openProgressDialog(e.files.length); //this is existing code, works fine
    }

target.result doesn't seem to exist in the event e. And nothing works properly from that point on. e should probably be used inside a FileReader object's onload(), (as seen here and here) but i have no idea how to use a FileReader for my purpose, with kendo Upload.

EDIT:
I did some more reading and now i am using FileReader like this:

    var reader = new FileReader();
    reader.onload = function (e) {
        // do the jszip stuff here with e.target.result
    };
    reader.onerror = function (e) {
        console.error(e);
    };  
    reader.readAsArrayBuffer(file);

Note : file = e.files[0] as in the 1st code block. With this though, i get the error:

Failed to execute 'readAsArrayBuffer' on 'FileReader': parameter 1 is not of type 'Blob'.

Community
  • 1
  • 1
insanity
  • 347
  • 3
  • 14
  • When I use a debugger on http://stuk.github.io/jszip/documentation/examples/read-local-file-api.html the type of `evt.target.files[0]` is a File which *is* a Blob. Which browser do you use ? – David Duponchel Mar 25 '15 at 18:23
  • I tested http://jsfiddle.net/5xmbnn6g/ in chromium without issue. The two things that I changed from the code you posted are : bind on `change` (the function name suggests otherwise) and use `e.target.files[0]` instead of `e.files[0]`. If you still have the issue, could you create a sample with jsfiddle ? – David Duponchel Mar 26 '15 at 23:33

0 Answers0