0
votes

im currently working on a dicom file upload system that uploads .dcm files with jquery file uploader. It is working fine but as DICOM data-sets can get very large i want to compress the files with JSZip before the upload.

Simply i am passing the file object to a zip function that returns the zipped file object. This is working fine with commonly known files but not with DICOM files. I've already tried to encode the files to base64 string before zipping but that doesn't work either. JSZip always throws me the following error:

Uncaught Error: The data of 'IM-0001-0001.dcm' is in an unsupported format !

I am using the following file compress function:

compressFile: function(data) {

    var zip = new JSZip();

    var file = data.files[0];

    zip.file(file.name, file, {binary:false});

    content = zip.generate({
        compression: 'DEFLATE'
    });

    return content;
}

I have also tried with base64 and binary in the .file options but that didn't made the trick.

Has anyone a clue on how to get that working? Im a beginner to JS so im sorry for noobish questions ^^

Kind Regards

1
This has nothing to do with DICOM. JSZip doesn't know the file is DICOM versus any other kind of binary data. The second argument to zip.file() should be data -- such as an Array or ArrayBuffer. That's most likely your issue. - martinez314
@whiskeyspider is right, the issue is the type of data.files[0]. Do you know the type of it ? - David Duponchel
data.files[0] is a File object. I have already modified my code to translate that to a base64 but that results in a empty zip. i'll try out your suggestions on monday. thanks - user285814

1 Answers

0
votes

You need to use a FileReader to read the content of data.files[0] first:

var reader = new FileReader();
reader.onload = (function(e) {
  var zip = new JSZip(e.target.result);

  var result = zip.generate({
    compression: 'DEFLATE'
  });

  // do something with result
}
reader.readAsArrayBuffer(data.files[0]);

See also this example.

Warning, FileReader is asynchronous: you can't make your function returns the result.