These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:20 pm Advanced search

Downloading files in localstorage

Here you can discuss things related to HTML and the Web in general that do not fit in to other categories.

Downloading files in localstorage

Postby concealed » Thu Oct 14, 2010 10:50 pm

I am intrigued by the drag-upload functionality so that your client-side javascript can have easy access to the bytes of a user's files such as text, image, doc, pdf, xml, etc. However, I have not seen good methods of allowing users to download items in localstorage. Use cases such as allowing a user to "upload" an image, your javascript then edits that image and allows them to download it again, OR maybe upload a doc and the javascript app populates and modifies the doc in a useful way (such as filling in fields).

I've seen the drag to desktop file downloader and think it's neat, but it only works in chrome for now and may not always be as practical was prompting a user to "save as..." I do understand that there is a DATA URI method of directing the user to a url with the base64. (data:image/png;base64,[.......................]), but this doesn't seem to work for all mine/application types across all browsers (think DOC and PDF).

So I was wondering what are the options to allow a user to download a file to disk using modern HTML 5 features (or legacy).

Thanks!
concealed
<h6>
 
Posts: 2
Joined: Thu Oct 14, 2010 10:22 pm

Postby m0 » Sun Oct 17, 2010 5:29 pm

Hi concealed,

I think you asked more than one question or if I understood incorrectly :)

You can "JSONify" localStorage into a string like the following:
Code: Select all
JSON.stringify(localStorage)


And save the entire localStorage (JSON) into disk. The modern way (HTML5) to save a file to disk is by using FileWriter API:
http://www.w3.org/TR/file-writer-api/

It will soon come to Chromium. Very soon.
User avatar
m0
<h6>
 
Posts: 2
Joined: Sun Oct 17, 2010 5:22 pm
Location: Ottawa, Ontario

Postby concealed » Wed Jan 26, 2011 8:28 pm

Hi m0,

Thanks for the reply. What I am really looking for (as an end result) is to allow the user to download the file. This might require sending the file to the server and then back, but I want to try and avoid that.
concealed
<h6>
 
Posts: 2
Joined: Thu Oct 14, 2010 10:22 pm

Postby zcorpan » Wed Jan 26, 2011 11:32 pm

You could use something like <iframe src="data:application/octet-stream,...">. Not ideal since you can't assign a default filename or file type. If a round-trip to the server is acceptable, you can use Content-Disposition: attachment; filename=...

I don't know if FileWriter supports the use case of prompting to save a single file. Maybe it does. If it doesn't, you can send feedback to public-webapps@w3.org with your use case.
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests