Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download a text file created using HTML5 filespace api using javascript on chrome

I am trying to download a text file that i created using the file space api on chrome. I am unable to download it. I can only view it on the chrome browser itself.

location.href = fileEntry.toURL();

That is the line of code i currently use to download it.

Could i use content-disposition to force download a .txt file? if so, how?

like image 256
Praveen Avatar asked Aug 24 '11 18:08

Praveen


1 Answers

Check out the FileSaver interface: http://www.w3.org/TR/file-writer-api/#the-filesaver-interface.

Here's a sample that does what you want: http://oftn.org/projects/FileSaver.js/demo/

Here's an HTML5Rocks post that describes usage in more detail: http://updates.html5rocks.com/2011/08/Saving-generated-files-on-the-client-side

like image 111
Boris Smus Avatar answered Oct 03 '22 06:10

Boris Smus