21

For storing data offline WebApp can use:

But apparently there is no File Storage. Of course, there is a manifest-based caching, but it's just a cache and is not supposed to be used as a user data storage.

Does it mean that the user of WebApp is forced to use some sort of a cloud file storage?

Is there any way to save large files on user's local machine? Or maybe some way to select a local folder web application can use to store user data?

Edit. Security. HTML5 already has the ability to write big portions of data to user's local machine. I don't see any security issues if a browser will provide another, file-based abstraction to store data. It can be some virtual machine, virtual filesystem, whatever.

Hm, I think, it is possible to write JS filesystem and store it as a blob in SQL...

Similar questions.

Update: Hm... recently I've found this and this. Maybe it is what I'm looking for... Yes, it is! See the answer below.

Community
  • 1
  • 1
Vanuan
  • 31,770
  • 10
  • 98
  • 102

7 Answers7

17

At last, I've found it! Here's the answer:

I’ll have the DOMFileSystem with a side of read/write access please wrote:

Eric Uhrhane of Google has been working on the working draft of the File API: Directories and System specification which defines a set of APIs to create a sandboxed filesystem where a web app can read and write data to.

Wow! I'm so excited!

Vanuan
  • 31,770
  • 10
  • 98
  • 102
  • 4
    Upvote for not giving up and always looking. And kudos for coming back and providing an update. – mt3 Mar 24 '11 at 19:59
6

Why not use localStorage while the user is editing a document and the FileWriter API when they want to save it to disk? Most people are used to seeing a save dialog pop up when saving a document.

The only scenario I can think of that warrants userless access to the FileWriter API is an autosave feature, but autosaving to localStorage can be just as good.

Richard Poole
  • 3,946
  • 23
  • 29
  • 2
    Another scenario is a media player. How an HTML5 application is supposed to play user's files? – Vanuan Dec 09 '10 at 07:52
  • 1
    You could probably make a primitive media player with an `` (to allow the user to select the file) and JavaScript (to set the `src` attribute of the corresponding ` – Richard Poole Dec 13 '10 at 19:37
3

There is a way to save relatively large files to a users hard drive if you are willing to use Flash. Look into Downloadify:

http://www.bitrepository.com/downloadify-client-side-file-generation.html

Downloadify allows you to send data to a SWF and have that SWF create a file on the users machine. My recommendation would be to store the data via one of the methods you listed, Webstorage, sqlite database, etc. Put all your assets, including the SWF in the manifest file so everything is cached locally to the browser. You can then pull information from your db or webstorage and use the SWF to create the files you need.

I'm not sure if you will be able to read these files back into your web application.

Another option to save data is by using link tags with the data URI scheme. However, I'm not sure if it is supported in all the major browsers at the moment.

John Kramlich
  • 2,220
  • 17
  • 18
  • 1
    The current version of all major browsers support data URIs, but IE8 is limited to 32 KB, which limits its utility for "large" files. – Ken Dec 07 '10 at 15:19
1

For security reasons you can't write files to a user's local filesystem in case it gets used for nefarious purposes by evil people.

That's not likely to change, and that's a good thing.

Ian Devlin
  • 18,534
  • 6
  • 55
  • 73
  • I think that's not a good thing. WebApps are getting more "clouddy" and less "free". How about implementing offline notepad in HTML5? – Vanuan Oct 18 '10 at 18:37
  • 2
    I'm not saying about local filesystem. Some virtual "sandbox" filesystem would be fine. HTML5 already has the ability to read-write shared SQL database. What about allocating some empty folder for web app to store its data? – Vanuan Oct 19 '10 at 20:22
  • Read, write and make are all possible, with permissions. ie. File System API, Open/Save File Picker + create Writable . – dnaatwork.com Feb 28 '22 at 04:17
1

The HTML5 FileSystem API started landing in Chrome 8 and is fairly complete as of now (Chrome 11).

There's a nice tutorial on it here: http://www.html5rocks.com/tutorials/file/filesystem/

ebidel
  • 23,921
  • 3
  • 63
  • 76
0

http://fsojs.com wraps the FileSystem API effectively, if you want an easy solution

kwh
  • 364
  • 1
  • 3
  • 7
0

As mentioned by others here, the FileWriter and FileSystem APIs can be used to store files on a client's machine from the context of a browser tab/window.

However, there are several things pertaining to these APIs which you should be aware of:

  • Implementations of the APIs currently exist only in Chromium-based browsers (Chrome & Opera)
  • Both of the APIs were taken off of the W3C standards track on April 24, 2014, and as of now are proprietary
  • Removal of the (now proprietary) APIs from implementing browsers in the future is a possibility
  • A sandbox (a location on disk outside of which files can produce no effect) is used to store the files created with the APIs
  • A virtual file system (a directory structure which does not necessarily exist on disk in the same form that it does when accessed from within the browser) is used represent the files created with the APIs

IsolatedStorage, which hasn't been mentioned as of yet, also allows for file i/o from a tab/window context, but it is made available through solely through Silverlight and requires the use of managed code to access. It, like FileSystem, also exists in a sandbox and makes use of a virtual file system.

Given the high market penetration of both Chromium-based browsers and Silverlight (support for which, interestingly enough has been dropped by such browsers), you may find a solution which uses the first of the above approaches available on a client machine satisfactory.

BakedGoods, a Javascript library that establishes a uniform interface that can be used to conduct common storage operations in all native (including FileSystem), and some non-native (including IsolatedStorage) storage facilities, is an example of such a solution:

//Write file to first of either FileSystem or IsolatedStorage
bakedGoods.set({
    data: [{key: "testFile", value: "Hello world!", dataFormat: "text/plain"}],
    storageTypes: ["fileSystem", "silverlight"],
    options: {fileSystem:{storageType: Window.PERSISTENT}},
    complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj){}
});

Just for the sake of complete transparency, BakedGoods is maintained by this guy right here :) .

Kevin
  • 2,617
  • 29
  • 35