【发布时间】:2018-12-12 09:11:02
【问题描述】:
我正在尝试使用 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 请求?
有用的链接:
【问题讨论】:
标签: javascript post xmlhttprequest zip jszip