本文介绍了使用Cordova FileTransfer将文件下载到设备的Downloads文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cordova FileTransfer对象从url下载文件到设备.

I am using Cordova FileTransfer object to download a file from a url to device.

var fileTransfer = new FileTransfer();
var path = cordova.file.dataDirectory;
 fileTransfer.download(
        fileUrl,
        path + "/sample.pdf",
        function(theFile) {
            console.log("download complete: " + theFile.toURI());
            alert("File downloaded to "+cordova.file.dataDirectory);
        },
        function(error) {
            console.log(JSON.stringify(error));
        }
    );

在这种情况下,文件被下载到data/data/com.fileDemo/files/(由于无法访问此文件夹,我不确定下载是否成功.获取成功消息为download complete: file:///data/data/com.fileDemo/files/sample.pdf).如何使用相同的方法将文件下载到android设备的下载"文件夹?

In this case the file is downloaded to data/data/com.fileDemo/files/(I am not sure whether download is success as I can't access this folder. Getting success message as download complete: file:///data/data/com.fileDemo/files/sample.pdf).How can I use the same method to download a file to "Downloads" folder of the android device?

推荐答案

在Cordova中,使用FileTransfer,您可以请求TEMPORARYPERSISTENT文件系统

In Cordova, with FileTransfer, you can request TEMPORARY or PERSISTENT file system

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, gotFS, fail);
  • PERSISTENT将返回SD卡/手机内存的根目录
  • TEMPORARY将返回数据文件夹中的一个文件夹.
  • PERSISTENT will returns the root of the SD card/phone memory
  • TEMPORARY will return a folder inside the data folder.

引用 File API & FileTransfer 了解更多信息.

Refer File API & FileTransfer for more info.

这篇关于使用Cordova FileTransfer将文件下载到设备的Downloads文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 00:42