cordova: download from url to android download folder

夙愿已清 提交于 2020-05-13 07:52:12

问题


Well before i start i tried below answers from stack overflow.

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/

But no luck at all.

I am trying to download a file from internet. My target is to download the file in download folder on Android phone.

I tried all the above answers and also i have used cordova example from cordova site.

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);
}
                          };
};

Any advise how to achieve this.


回答1:


Fork,
you have to choose download file url,
local download file located here -
file:///storage/emulated/0/download This link may help you -

Cordova - Download a file in download folder

Added file transfer plugin to download such as -

https://github.com/cfjedimaster/Cordova-Examples/tree/master/asyncdownload

choose any as per requirement



来源:https://stackoverflow.com/questions/41129399/cordova-download-from-url-to-android-download-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!