Sunday, May 19, 2024
-1
rated 0 times [  4] [ 5]  / answers: 1 / hits: 65190  / 13 Years ago, tue, august 23, 2011, 12:00:00

I would like to know if I can create a text file and save the file in the users Downloads section in his/her computer using Javascript. The way my feature should work is when the user clicks the submit button, I populate the users info in the text file and then save it in his machine. I would like this to work in Google Chrome.



Is this possible? I have seen posts that specifically tell me that it is a serious security issue.


More From » google-chrome

 Answers
53

Sure you can, using the brand new APIs.



 window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;

window.requestFileSystem(window.TEMPORARY, 1024*1024, function(fs) {
fs.root.getFile('test.bin', {create: true}, function(fileEntry) { // test.bin is filename
fileEntry.createWriter(function(fileWriter) {
var arr = new Uint8Array(3); // data length

arr[0] = 97; // byte data; these are codes for 'abc'
arr[1] = 98;
arr[2] = 99;

var blob = new Blob([arr]);

fileWriter.addEventListener(writeend, function() {
// navigate to file, will download
location.href = fileEntry.toURL();
}, false);

fileWriter.write(blob);
}, function() {});
}, function() {});
}, function() {});

[#90474] Sunday, August 21, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deonkalvinw

Total Points: 409
Total Questions: 96
Total Answers: 89

Location: Saint Pierre and Miquelon
Member since Sun, Nov 27, 2022
2 Years ago
deonkalvinw questions
Sun, Feb 6, 22, 00:00, 2 Years ago
Tue, Dec 28, 21, 00:00, 2 Years ago
Sun, Aug 22, 21, 00:00, 3 Years ago
Sun, Mar 7, 21, 00:00, 3 Years ago
;