Jszip创建多个文件夹

时间:2018-04-05 05:47:08

标签: javascript angularjs jszip

zip name:testing.zip

当我提取文件时  测试\ https_ \ s3-us-west-2.amazonaws.com \文件\ 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);
                            });
                        }
                    });
                });
            }

1 个答案:

答案 0 :(得分:1)

最后这里是工作代码

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

替换为

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