gpt4 book ai didi

javascript - Jszip 创建多个文件夹

转载 作者:行者123 更新时间:2023-11-30 20:37:28 30 4
gpt4 key购买 nike

压缩包名称:testing.zip

当我提取文件时 测试\https_\s3-us-west-2.amazonaws.com\files\image.jpg

预期结构:testing/image.jpg

这是我的代码

            var urls = ['https://s3-us-west-2.amazonaws.com/files/image.jpg'];

var nombre = $scope.meetingName;
//The function is called
compressed_img(urls, nombre);

function compressed_img(urls, nombre) {
var zip = new JSZip();
var count = 0;
var name = nombre + ".zip";
urls.forEach(function (url) {
JSZipUtils.getBinaryContent(url, function (err, data) {
if (err) {
throw err;
}
zip.file(url, data, { binary: true });
count++;
if (count == urls.length) {
zip.generateAsync({ type: 'blob' }).then(function (content) {
saveAs(content, name);
});
}
});
});
}

最佳答案

最后是工作代码

 zip.file(url, data, { binary: true });

替换为

 var filename = url.replace(/.*\//g, "");
zip.file(filename, data, { binary: true, createFolders: true });

关于javascript - Jszip 创建多个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49664975/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com