8

With using Node-Webkit, I'm trying to create and write to a text file in a user defined local folder from within a web worker js file. I tried using requestFileSystemSync(), .root.getFile(), .createWriter(), etc. but I'm not sure where this file is saved (can it be written to an defined local folder, or is it "sandboxed" to a special folder location?).

Can anyone offer advice on the best way for me to create text files from a web worker to an arbitrary local folder location? That is, in the local file system outside of a sandboxed file system?

Thanks.

Markus Amalthea Magnuson
  • 8,415
  • 4
  • 41
  • 49
cohoman
  • 329
  • 1
  • 5
  • 18
  • I'm quite curious what type of application you're writing. If you don't mind me asking, what are the web-workers for and why do you need to write everywhere on the file system? – Nathan Breit Aug 07 '13 at 06:24

1 Answers1

17

It sounds like you might be trying to use the web filesystem API. That might be a reasonable solution, it would allow you to run your app as a regular webpage, however the web filesystem API is sandboxed.

node-webkit offers "Complete support for Node.js APIs," which I think means you can use the node.js file system API to write anywhere on the file system. Pretty cool. So something like this should work:

var fs = require('fs');
fs.writeFile("path/to/anywhere/test.txt", "Hi mom!", function(err) {
    if(err) {
        alert("error");
    }
});

Also, node-webkit web-workers do not support require I hear. So you'll need to do your filesystem stuff in your main thread.

Nathan Breit
  • 1,661
  • 13
  • 33
  • Thanks you for that info and tip. After lots of Googling, I've also concluded that it isn't possible to write to a local file from a web worker. As such, I'll do as you've suggested and do the actual file writing from my main thread. Thanks again! – cohoman Aug 07 '13 at 14:10