Reputation: 540
Is there a way how to programmaticly download the file from the server (user clicks save button in the web app) and the browser(supporting File API) or device will download the file and save it in its sand-boxed file system? I'm looking at the HTML5 File API. I can create or amend the file and store it, but first I need to get the file from server. Simply said I want to avoid the save as pop up window and I want the file stay within sandboxed file system of web application. Any suggestions where I can look is welcomed.
Upvotes: 3
Views: 1760
Reputation: 1340
Origin private file system (OPFS) is what you were looking for. https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system
The origin private file system (OPFS) is a storage endpoint provided as part of the File System API, which is private to the origin of the page and not visible to the user like the regular file system.
Upvotes: 0
Reputation: 312
You want XMLHttpRequest(), which despite its name, can handle downloading all types of data including binary. If you set the responseType to "arraybuffer", you can convert that to a blob and save it to the file system pretty easily.
HTML5Rocks has a great tutorial that should cover everything you need: New Tricks in XMLHttpRequest
(I know this question is a bit old, but I was just searching for how to do the same thing and it was the first result that popped up, so I thought I'd share)
Upvotes: 2
Reputation: 35795
The simplest way to download a file is simply to window.open
the URL to it. This will prompt the user to pick somewhere to save the file.
Other than that, there's not a ton you can do; browsers protect their users' file systems very carefully.
Upvotes: 0