是否可以在自定義位置( /home/Users/user1/ ) 中保存名為 file1.txt的文件。
我有以下代碼: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'}));
});
});
});
});
使用這裡代碼,我得到提示,因此需要選擇目錄,但不需要它,我想在設置中聲明目錄位置。
這裡解決方案的任何解決方案?
編輯
根據 @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'}));
});
});
});