Question

I have started to look in to Googles Packaged Apps in Chrome, http://developer.chrome.com/apps which seems to be a great technology, but in an early stage.

My question is: Is it's possible to save files to the computer using the fileSystem API from the app without a prompt? I want to make an app that can save log files etc.

Was it helpful?

Solution

I had some conversations with people involved in the packaged apps development and as it is today you cant have access to the file system without prompt our outside of an apps sandbox. But it might come in the future.

But there is a new project called Node-Webkit that is very similar to Chrome packaged apps where you develop your app in Chrome with HTML, js etc where you also can run nodejs in the browser. Using this you can access the file system and many more things.

Check it out here: https://github.com/rogerwang/node-webkit and https://github.com/rogerwang/node-webkit/wiki

Loading and saving files in Node-Webkit is very easy. It looks like this

var gui = require("nw.gui");
var fs = require("fs");

//Save
fs.writeFile('message.txt', 'Hello Node', function (err) {
    if (err) throw err;
    console.log('It\'s saved!');
});

//Load
fs.readFile('message2.txt', 'utf8', function (err, data) {
    if (err) throw err;
    console.log(data);
});

OTHER TIPS

It looks like you will soon be able to do this -- see https://groups.google.com/a/chromium.org/forum/#!topic/apps-dev/fu1TyjdYLEc

Kind of. You can save to your app's "workspace", which means the file will be saved, but the user or other apps won't have access to it. It will be in a sandboxed storage area. To do it, just use the HTML5 Filesystem API (tutorial here).

You need: "permissions": ["storage"] in your manifest, and in your js you can do:

var onInitFsCallback=function(fs) {
  fs.root.getFile('log.txt', {create: true}, function(fileEntry) {
    fileEntry.createWriter(function(fileWriter) {
      _this.fileWriter = fileWriter;
      fileWriter.onwriteend = onWriteEndCallback;
      fileWriter.onerror = onErrorCallback;
      fileWriter.write(myBlob);
      fileWriter.write(myString);
    }, errorHandler);

  }, errorHandler);

};
window.webkitRequestFileSystem([window.TEMPORARY or window.PERMANENT], sizeInBytes,
  onInitFsCallback, onErrorCallback);

You can also inspect your app's filesystem with Inspector Tools (Resources -> Filesystem). From there, you can either download or delete files. In Chrome 24, you need to Enable Developer Tools experiments in chrome://flags, click on the DevTools settings menu, Experiments, and enable the FileSystem inspection.

On the other hand, if you want to save in an arbitrary location outside of your app's sandbox, the user prompt is required for security reasons.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top