我试图使用zip文件“post”和“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,它根本不会运行它,它不会显示错误。
如何格式化zip以处理xhr请求?
有用的链接:
发布于 2018-07-04 04:31:17
你为什么不试试这样
zip.generateAsync({type:"blob"}).then(function(content) {
var data = new FormData();
data.append("files", content, "Test.zip");
});https://stackoverflow.com/questions/51164991
复制相似问题