Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript prompt for download location

// ...
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);
      }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #prompt #download #location
ADD COMMENT
Topic
Name
7+9 =