我正在使用Cordova FileTransfer对象将文件从url下载到设备.
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));
}
);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,文件被下载到data/data/com.fileDemo/files/
(我不确定下载是否成功,因为我无法访问此文件夹.获取成功消息download complete: file:///data/data/com.fileDemo/files/sample.pdf).如何使用相同的方法将文件下载到Android设备的"下载"文件夹?
在 Cordova 中,使用 FileTransfer,您可以请求TEMPORARY或PERSISTENT文件系统
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, gotFS, fail);
Run Code Online (Sandbox Code Playgroud)
- IOS
PERSISTENT将返回 Documents 目录,TEMPORARY将返回缓存目录- 安卓
PERSISTENT将返回 SD 卡/手机内存的根目录TEMPORARY将返回数据文件夹内的文件夹。
参考File API&FileTransfer了解更多信息。
| 归档时间: |
|
| 查看次数: |
5973 次 |
| 最近记录: |