2014-09-24 89 views
1

該事件處理程序似乎永遠不會被調用。成功回調通過罰款和下載工程。有什麼我在這裏做錯了嗎?FileTransfer onprogress無法正常工作 - PhoneGap 3.5.0

filesystem.root.getFile('/path/to/file', { create: true }, function (file) { 

    var transfer = new FileTransfer(); 

    transfer.onprogress = function() { 
     console.log(arguments); 
    }; 

    transfer.download(
     'http://example.com/path/to/file', 
     file.toURL(), 
     function() { console.log('success'); }, 
     function() { console.log('error'); }, 
     true 
    ); 

}, function() { console.log('error'); }); 

該應用程序使用PhoneGap 3.5.0與最新的文件和文件傳輸插件。我在onprogress定義功能在iPad上測試與iOS 8

回答

0

你似乎缺少參數變量。

它應該是:

transfer.onprogress = function (progressEvent) { 
    console.log(progressEvent); 
    console.log(progressEvent.loaded); //Loaded bytes 
    console.log(progressEvent.total); //Total bytes 
    console.log(progressEvent.lengthComputable); //TRUE if the destination server informs total file length 
}; 

你可以在這裏找到文檔:http://docs.phonegap.com/en/edge/cordova_file_file.md.html#FileTransfer

希望它能幫助!

+1

我的應用程序沒有觸發進展功能。這與提供的示例相同。有任何想法嗎? Cordova 6.3.1 - 文件傳輸1.5.1 – 2016-09-21 11:02:04

+1

這似乎是Apache File Transfer插件中的一個已知錯誤,請參閱https://issues.apache.org/jira/browse/CB-9936 – tonesforchris 2016-11-11 00:20:28

+0

@tonesforchris是否有解決方案爲錯誤?我跟着你的鏈接,但那裏的討論沒有看到任何結果。 – 2017-07-16 04:42:55