2017-10-11 52 views
0

我使用IonicNative插件下載PDF文件。下載不能使用filetransfer插件

https://ionicframework.com/docs/native/file-transfer/

我可以看到完整下載使用警報,但不能看到任何下載發生。

private filetransfer: FileTransferObject = this.transfer.create(); 
    const url = 'https://www.example.com/example%20test.pdf'; 
    this.filetransfer.download(url, this.file.dataDirectory + 'example%20test.pdf').then((entry) => 
      { 
        alert('download complete: ' + entry.toURL()); 
      }, 
(error) => { 
        alert(error); 
}); 

這是正確的做法還是缺少一些東西?

回答

0

這看起來像是正確的做法。

我不能確定你的意思是「你看不到任何下載發生」,但我假設你無法在文件系統中找到該文件(否則只是讓我知道)。

在這種情況下,你保存在一個私人數據存儲的文件,由指定的:

this.file.dataDirectory 

如果用this.file.externalDataDirectory替換this.file.dataDirectory,你會發現在你的文件的文檔系統(類似於:file:///storage/emulated/0/Android/data/com.project.name)。

離子本地文檔不是在這種情況下說的好,看到科爾多瓦文件的插件文件代替,其中不同的possibilitiers列出:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#where-to-store-files

+0

嗨@JudgeFudge我有一個Cordova filetransfer的類似問題。成功函數的下載被立即調用(沒有調用正在進行!),當我瀏覽文件時,它在那裏但是空的(0字節)。我下載的服務器有點慢(我試過從瀏覽器中下載比平時花費的時間更長)。我不知道該怎麼辦! – Aelgawad

相關問題