HTML5选择文件位置,html5 chrome.filesystem 保存文件无提示位置_html5_开发99编程知识库...

是否可以在自定義位置( /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'}));

});

});

});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值