I my application to create a directory on a FirefoxOS device.
Anyone knows how to do that?
[Addition] how to create file
- [SDCard] = navigator.getDeviceStorage( 'sdcard' )
- [Blob Object] = new Blob()
- [SDCard].addNamed( [Blob Object], fileName )
I my application to create a directory on a FirefoxOS device.
Anyone knows how to do that?
[Addition] how to create file
You have to use the full path relative to the device storage. Directories are automatically created for you when you save a file with addNamed
. Let say want to save a file named test.txt
in the folder examples
of the sdcard.
Then you'll have to save the blob with the name examples/test.txt
.
var sdcard = navigator.getDeviceStorage("sdcard");
var file = new Blob(["This is a text file."], {type: "text/plain"});
var request = sdcard.addNamed(file, "examples/test.txt");
request.onsuccess = function () {
var name = this.result.name;
console.log('File "' + name + '" successfully wrote on the sdcard storage area');
}
request.onerror = function () {
console.warn('Unable to write the file: ' + this.error);
}
Here read this from the MDN documentation:
Note: Repository in a storage area is implicit; it's not possible to explicitly create an empty repository. If you want to use a repository structure you have to make it part of the name of the file to store. So if you want to store the file bar inside the foo repository, you have to provide the complete path name of the file: addNamed(blob, "foo/bar").
As files are added in a given restricted storage area, for security reasons, a file path name cannot start with "/" nor "../" (and "./" is pointless).