首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >下载多个文件和zip - Chrome扩展

问下载多个文件和zip - Chrome扩展
EN

Stack Overflow用户
提问于 2013-01-06 15:52:44
回答 2查看 6.5K关注 0票数 7

是否可以将多个图像下载到沙箱文件系统中(没有“另存为”对话框,或最多一次另存为对话框)?

下载后,我想把它们压缩成一个..有没有javascript档案库?

提前谢谢..

EN

回答 2

Stack Overflow用户

发布于 2013-01-06 20:48:59

您可以使用zip.js来实现这一点。它已经有了从HTTP获取压缩内容的API (参见zip.HttpReader构造器),并用于在HTML5文件系统上写入生成的压缩文件(参见zip.FileWriter构造函数)。

下面是一个使用filesystem API的示例

index.html文件:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Zip JSON data from the BBC into HTML5 FileSystem</title>
</head>
<body>
  <script src="zip.js"></script>
  <script src="zip-fs.js"></script>
  <script src="zip-ext.js"></script>
  <script src="example.js"></script>
</body>
</html>

example.js文件:

代码语言:javascript
复制
// 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);
  });
}
票数 6
EN

Stack Overflow用户

发布于 2013-01-06 18:30:30

您可以将图片作为某些网页的常规部分进行访问,也可以通过XMLHTTPRequests单独下载图片。之后,您可以使用JSZip JavaScript库将图片压缩到一个单独的归档中。zip可以存储为一个文件,而不需要“另存为”对话框(在网站上试试这个例子)。虽然我不确定你为什么需要sandbox。

还有其他用于压缩的JavaScript库,例如,other SO answer中提到的一些库。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14180375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档