chrome.filesystem guardar archivo sin ubicación de solicitud
¿Puedo guardar el archivo en una ubicación personalizada (/home/Users/user1/
) con nombrefile1.txt
.
Tengo este codigo:
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'}));
});
});
});
});
Con este código, recibo un mensaje por lo que necesito elegir el directorio, pero quiero sin eso, quiero declarar la ubicación del directorio en la configuración.
¿Alguna solución para esto?
EDITAR
Según la respuesta aceptada de @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'}));
});
});
});