2015-07-28 54 views
0

中脫機訪問是否可以從類似於「hxxp://abc.org/img.png」的鏈接下載文件,然後將其保存在本地系統中。 (用戶不應選擇目錄或僅選擇一次)。一旦數據保存在客戶端計算機上,我可以打開該位置並使用任何文件?本地保存文件以便在Chrome瀏覽器APP

這基本上是離線運行我的應用程序(鉻應用程序)。 我已經看到了chrome應用程序的fileSystem API,它可以打開一個文件並修改它,但沒有看到如何下載文件並保存它。

請指導如何實現這一目標。

+0

也許你可以使用'chrome.downloads.download'來下載一個URL。在此處查看更多詳細信息:https://developer.chrome.com/extensions/downloads#method-download – gui47

+0

@ gui47已經檢查過,下載API僅與擴展程序兼容,不適用於Chrome應用程序 –

+0

嗯,據我所知,沒有類似Chrome Chrome的Chrome應用程序。我不知道也許Html5下載屬性可以幫助你。 – gui47

回答

1

我使用fetch apt for this propouses。

var myHeaders = new Headers(); 
    myHeaders.append('pragma', 'no-cache'); 
    myHeaders.append('cache-control', 'no-cache'); 

    var myInit = { 
     method: 'GET', 
     headers: myHeaders, 
    }; 

    fetch(path, myInit) 
     .then(function (response) { 
      return response.blob(); 
     }) 
     .then(function (myBlob) { 
      File.system.root.getFile(filename, {create: true}, function (entry) { 
       entry.createWriter(function (writer) { 
        writer.write(myBlob);.... 
相關問題