js多文件下载和多文件分文件夹打包下载并重命名
Posted 初辰ge
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js多文件下载和多文件分文件夹打包下载并重命名相关的知识,希望对你有一定的参考价值。
js多文件下载并重命名
let list=['...']
function downloadFile(list,index)//下载文件方法
if(index>=list.length)
return
let url=list[index];
const x = new window.XMLHttpRequest();
x.open('GET', url, true);
x.responseType = 'blob';
var fileName = url.substring(url.lastIndexOf("."),url.length);
x.onload = () =>
const url = window.URL.createObjectURL(x.response);
const a = document.createElement('a');
a.href = url;
a.download = "每日意见反馈表"+(index+1)+fileName;
a.click();
downloadFile(list,index+1)
;
x.send();
downloadFile(list,0)
js多文件重命名打包Zip压缩包并下载此压缩包
// <script src="https://cdn.bootcdn.net/ajax/libs/jszip/3.6.0/jszip.min.js"></script>
// <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
let list=[
namne:'文件名',
url:'...'
]
async function downloadFileZip(list,zipName)
var zip = new JSZip();
for (let i = 0; i < list.length; i++)
let data = await axios(
method: "get",
url: list[i].url,
responseType: "blob",
);
zip.file(list[i].name, data);
zip.generateAsync(type: "blob").then(function (content)
let url = window.URL.createObjectURL(content);
downloadFile(url, zipName);
);
downloadFileZip(list,'压缩包名')
js多文件重命名分文件夹打包Zip压缩包并下载此压缩包
var zip = new JSZip();
for (let i = 0; i < res.data.length; i++)
let stuObj = res.data[i]
let rName = stuObj.realName
let list=[
namne:'文件名',
url:'...'
]
let folder = zip.folder(rName);
for (let j = 0; j < list.length; j++)
let data = await axios(
method: "get",
url: list[j].url,
responseType: "blob",
);
folder.file(rName + '-' + list[j].name, data);
zip.generateAsync(type: "blob").then(function (content)
let url = window.URL.createObjectURL(content);
downloadFile(url, $("#classesId").find('option:selected').text());
);
以上是关于js多文件下载和多文件分文件夹打包下载并重命名的主要内容,如果未能解决你的问题,请参考以下文章