prompt de javascript para download localização
// ...
const blob = new Blob(/*...*/);
// Use File System Access API
saveFileToDisk(blob, 'Some-File.txt')
async saveFileToDisk({blob, fileName}){
try {
const fileHandle = await self.showSaveFilePicker({
suggestedName: fileName,
types: [
{
description: "File",
// ...
},
],
});
const writeFile = async (fileHandle, contents) => {
// Create a FileSystemWritableFileStream to write to.
const writable = await fileHandle.createWritable();
// Write the contents of the file to the stream.
await writable.write(contents);
// Close the file and write the contents to disk.
await writable.close();
};
// write file
writeFile(fileHandle, blob).then(() => console.log("FILE DOWNLOADED!!!"));
} catch (error) {
console.log(error);
}
}
Spotless Stoat