问题
Q: Is there a way to default or suggest a folder structure on a direct download without using a zip file?
I have an AngularJS app that I use to generate text files that are imported into a commercial machine. In order for the import to work, the file has to be embedded in a particular folder structure. Is there a way to suggest this folder structure via the download dialog without having to use a zip file?
We use a zip today, but Windows users are having problems with the extracts working on the machine (see this question). Curious if there was a way to bypass the zip altogether.
Relevant info:
- Angular version: 5.2.10
- Zip Utility in angular: JSZip 3.1.5
JSZip code:
const zip = new JSZip();
zip.folder('FolderA/FolderB/FolderC').file('FILE.TXT', new File([contentString], 'TEMP.TXT', { type: 'text/plain' }));
zip.generateAsync({ type: 'blob' })
.then(function (content) {
saveAs(content, 'ZipFile.ZIP');
});
回答1:
You could use tar instead of zip.
https://github.com/beatgammit/tar-js
But no, you you can't download a directory unless it's somehow converted to a single file.
来源:https://stackoverflow.com/questions/51315153/is-there-a-way-to-default-or-suggest-a-folder-structure-on-a-direct-download-wit