can i save file in custom location (/home/Users/user1/
) with name file1.txt
.
I have this code:
chrome.fileSystem.chooseEntry({type:'openDirectory'}, function(entry) { chrome.fileSystem.getWritableEntry(entry, function(entry) { entry.getFile('file1.txt', {create:true}, function(entry) { entry.createWriter(function(writer) { writer.write(new Blob(['Lorem'], {type: 'text/plain'})); }); }); }); });
With this code, i get prompt so i need to choose directory, but i want without that, i wanna declare directory location in settings.
Any solution for this?
EDIT
According to accepted answer from @Xan :
// set location $('#location_field').on('click', function(){ chrome.fileSystem.chooseEntry({type:'openDirectory'}, function(entry) { chrome.storage.sync.set({'print_location': chrome.fileSystem.retainEntry(entry)}); }); }); // get location var print_location = null; chrome.storage.sync.get({ print_location: null }, function(items){ chrome.fileSystem.restoreEntry(items.print_location, function(entry){ print_location = entry; }); }); // save file chrome.fileSystem.getWritableEntry(print_location, function(entry) { entry.getFile('file1.txt', {create:true}, function(entry) { entry.createWriter(function(writer) { writer.write(new Blob(['Lorem'], {type: 'text/plain'})); }); }); });