Search code examples
javascriptfile-uploaddirectoryarchive

How to create folder, files in this folder, compress folder (in zip or rar file) and upload this to the desktop with Javascript?


For a web application, an user must be able to export an html file with css stylesheet of choice (proposed by the application) on his desktop.

A unique button for export : on click, a "Save as" dialog window appears for choose a destination on desktop. The file must have extension .zip (or .rar) and he contains html and css files.

How can I do this (without library) ? Thanks.


Solution

  • You can use the JSZip library to do this https://stuk.github.io/jszip/

    var zip = new JSZip();
    zip.file("Hello.txt", "Hello World\n");
    var img = zip.folder("images");
    img.file("smile.gif", imgData, {base64: true});
    var content = zip.generate({type:"blob"});
    saveAs(content, "example.zip");