Search
 
SCRIPT & CODE EXAMPLE
 

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);
      }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: React modal input field auto focus antd 
Javascript :: mongodb count conditional array items 
Javascript :: Codewars Convert a String to a Number! 
Javascript :: jquery hover 
Javascript :: gmail regex 
Javascript :: create new angular component command 
Javascript :: disable back button in react native 
Javascript :: javascript save result to file 
Javascript :: express serve static files 
Javascript :: check if input is required jquery 
Javascript :: jquery get value by name 
Javascript :: observable.create is deprecated 
Javascript :: view all local storage js 
Javascript :: in array in js 
Javascript :: gdscript add child node 
Javascript :: jquery ajax type json 
Javascript :: trigger ctrl + p or print page with javascript 
Javascript :: jquery on input 
Javascript :: map function react not appearing 
Javascript :: datatable desc active 
Javascript :: change header background color on scroll css 
Javascript :: javascript get text from paragraph 
Javascript :: find particular object from array in js 
Javascript :: js substring 
Javascript :: js check query string 
Javascript :: jquery delay 
Javascript :: angular lifecycle hooks 
Javascript :: create file node javascript 
Javascript :: javascript array insert at 0 
Javascript :: react proptypes reuse shape 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =