Skip to content Skip to sidebar Skip to footer

Need To Zip The Selected File From Client Machine When Uploading (using Jszip) In .net Web App. The Zipped File Should Be Uploaded To Server Location

I am new to using JSZIP and may be asking an obvious question. But here goes: I am using the File Upload control to upload a file to server. The source file is in a path on the Cli

Solution 1:

Once your zip is constructed, you can post it to the server using jQuery as follows.

var zipData = zip.generate({ type: "base64" });

var formData = newFormData();
formData.append('zipData', zipData);

var postToServer = $.ajax({
    type: "POST",
    url: "Upload", // My server-side MVC controller has an action named Uploaddata: formData,
    processData: false,
    contentType: false,
});

postToServer.done(function () {
    ...
});

postToServer.fail(function( jqXHR, textStatus ) {
    ...
});

At the server end you will need code to receive the data stream and save it there using whatever server-side technology you've chosen.

Solution 2:

I don't have time right now to post my exact code, and this question is old and abandoned.

But the benefit of ZIP on client is indeed that you can upload multiple files in one. This may have been different 5 years ago. But the outline of the solution is this:

  1. you use the file chooser object to get the File objects
  2. you create a JZIP object and you create workers with the File objects
  3. finally you submit your zip file by sending it to the XHR object.

This can all be done very neatly in a streaming fashion, but in order to enjoy doing that you need to absolutely learn to use continuation-passing style coding in JavaScript and never assume synchronous returns from functions with the data ready to go. (A common beginner's mistake, and a constant pain for those people who don't completely embrace the continuation passing style as a beautiful concept.)

If there is any interest / replies / comments / upvotes I will come back and paste some code from my working version.

Post a Comment for "Need To Zip The Selected File From Client Machine When Uploading (using Jszip) In .net Web App. The Zipped File Should Be Uploaded To Server Location"