Downloading multiple files and zip - Chrome extension

前端 未结 2 1762
小蘑菇
小蘑菇 2020-12-31 22:48

Is it possible to download multiple images into the sandbox file system (without the \"save as\" dialog box, or at-max one saveas dialog) ?

after downloading them,

2条回答
  •  無奈伤痛
    2020-12-31 23:03

    You can use zip.js for this. It does already have API for fetching contents to be zipped from HTTP (cf. zip.HttpReader constructor) and for writing generated zip on HTML5 filesystem (cf. zip.FileWriter constructor).

    Here is an example using the filesystem API:

    index.html file:

    
    
    
    
    Zip JSON data from the BBC into HTML5 FileSystem
    
    
      
      
      
      
    
    
    

    example.js file:

    // create a zip virtual filesystem
    var fs = new zip.fs.FS();
    
    // add some files into the zip filesystem 
    
    // add the "bbc-music.json" file in the root directory
    fs.root.addHttpContent("bbc-music.json", 
      "http://www.bbc.co.uk/programmes/genres/music.json");
    // add the "bbc-learning.json" file in the root directory
    fs.root.addHttpContent("bbc-learning.json", 
      "http://www.bbc.co.uk/programmes/genres/learning.json");
    
    // create a file named "test.zip" in the root directory of the HTML5 filesystem 
    createFile("test.zip", function(fileEntry) {
      // export the zip content into "test.zip" file
      fs.root.exportFileEntry(fileEntry, function() {
        console.log("done");
      });
    });
    
    // function to create a file in the HTML5 temporary filesystem
    function createFile(filename, callback) {
      webkitRequestFileSystem(TEMPORARY, 4 * 1024 * 1024, function(fs) {
        fs.root.getFile(filename, { create : true }, callback);
      });
    }
    

提交回复
热议问题