我正在尝试使用 zip 文件"发布"和 xhr 请求,但我无法以正确的格式获取 zip。我找到了一个帖子,它显示了类似的请求:
var zip = new JSZip(); // create the jszip zip
var input = $("#image")[0]; // Get the image from dom (image is an input button)
zip.file("test.png", input.files[0], {base64: true}); // Add uploaded image to zip
var content = zip.generate({type:"blob"}); // Format zip to blob
//prepare file for api call
var data = new FormData();
data.append("files", content, "Test.zip");
首先,zip.generate({type:"blob"});
已被弃用。升级指南指出:
// 2.x
zip.generate();
// 3.x
zip.generateAsync({type:"uint8array"})
.then(function (content) {
// use content
});
我不明白什么是"使用内容"。如果我只是将该函数留空,代码将无法运行。我会列出错误,但我使用的是SAP WEB IDE,它根本不会运行它,它不会显示错误。
如何格式化 zip 以用于 xhr 请求?
有用的链接:
- JSZip升级指南
- 过时的帖子示例
你为什么不试试这种方式
zip.generateAsync({type:"blob"}).then(function(content) {
var data = new FormData();
data.append("files", content, "Test.zip");
});
在这里查看 https://github.com/Stuk/jszip