2016-12-13 105 views
0

在我開始之前,我嘗試了下面的堆棧溢出答案。科爾多瓦:從網址下載到Android下載文件夾

Download file to downloads folder ios/android using phonegap

FileTransfer Cordova download path

Download a file to Downloads folder of device using Cordova FileTransfer

http://www.phonegaptutorial.com/downloading-an-image-from-the-internet-with-phonegap/

,但沒有運氣可言。

我正試圖從互聯網上下載文件。 我的目標是在Android手機上的下載文件夾中下載文件。

我嘗試了所有上述的答案,我也使用了科爾多瓦網站的科爾多瓦例子。

https://cordova.apache.org/docs/en/2.0.0/cordova/file/filetransfer/filetransfer.html

function downloadCL(){ 

var url = "http://www.phonegaptutorial.com/wp-content/uploads/examples/phonegap-logo.png"; 

// we need to access LocalFileSystem 
window.requestFileSystem(window.LocalFileSystem.PERSISTENT, 0, function(fs) 
{ 
    // create the download directory is doesn't exist 
    fs.root.getDirectory('downloads', { create: true }); 

    // we will save file in .. downloads/phonegap-logo.png 
    var filePath = fs.root.fullPath + '/downloads/' + url.split('/').pop(); 
    var fileTransfer = new window.FileTransfer(); 
    var uri = encodeURI(decodeURIComponent(url)); 

    fileTransfer.download(uri, filePath, function(entry) 
    { 
     alert("Successfully downloaded file, full path is " + entry.fullPath); 
    }, 
    function(error) 
    { 
     console.log("Some error " + error.code + " for " + url +); 
    }, 
    false); 
} 
          }; 
}; 

任何建議如何實現這一目標。

+0

爲什麼要投票?它有什麼問題?至少評論原因。 – Ironic

回答