带有JSZIPJavaScript/JSZip升级的xhr Post

带有JSZIPJavaScript/JSZip升级的xhr Post,javascript,post,xmlhttprequest,zip,jszip,Javascript,Post,Xmlhttprequest,Zip,Jszip,我正在尝试使用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}); //

我正在尝试使用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 WEB IDE,它根本不会运行,也不会显示错误

如何格式化zip以满足xhr请求


有用链接:


    • 你为什么不试试这种方法

      zip.generateAsync({type:"blob"}).then(function(content) {
        var data = new FormData();
        data.append("files", content, "Test.zip");
      });
      
      在这里检查

      我唯一改变的是移动“var data=new FormData();”命令在这个函数之外,以便以后可以在xhr调用中引用它。谢谢