为什么cordova.file.documentsDirectory为null? [英] Why is cordova.file.documentsDirectory null?
问题描述
我正在尝试在 http://ngcordova.com/上使用cordova-plugin-file-transfer docs / plugins / fileTransfer /
指定下载位置的示例代码如下。
The example code to specify the download location is as follows.
var targetPath = cordova.file.documentsDirectory + "testImage.png";
但是,此属性不存在。我已经记录 console.log(JSON.stringify(cordova.file))
,我得到以下输出(格式化)。
However, this property does not exist. I've logged console.log(JSON.stringify(cordova.file))
and I get the following output (formatted).
{
"applicationDirectory": "file:///android_asset/",
"applicationStorageDirectory": "file:///data/data/com.ionicframework.mobile379071/",
"dataDirectory": "file:///data/data/com.ionicframework.mobile379071/files/",
"cacheDirectory": "file:///data/data/com.ionicframework.mobile379071/cache/",
"externalApplicationStorageDirectory": "file:///storage/emulated/0/Android/data/com.ionicframework.mobile379071/",
"externalDataDirectory": "file:///storage/emulated/0/Android/data/com.ionicframework.mobile379071/files/",
"externalCacheDirectory": "file:///storage/emulated/0/Android/data/com.ionicframework.mobile379071/cache/",
"externalRootDirectory": "file:///storage/emulated/0/",
"tempDirectory": null,
"syncedDataDirectory": null,
"documentsDirectory": null,
"sharedDirectory": null
}
此外,我已经从这里得到了一些提示 https://cordova.apache.org/docs/en/dev/ cordova-plugin-file / 并修改了我的config.xml并进行了以下更改。
Furthermore, I've followed some hints from here https://cordova.apache.org/docs/en/dev/cordova-plugin-file/ and modified my config.xml with the following changes.
<preference name="AndroidPersistentFileLocation" value="Internal" />
<preference name="iosPersistentFileLocation" value="Library" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" />
此代码不是在模拟器或浏览器上运行,而是真正的Android设备。关于为什么这个属性为null的任何想法?
This code is NOT running on an emulator or a browser, but a real android device. Any ideas on why this property is null?
当我尝试下载文件时,我得到的只是一个错误。我的代码如下所示。
When I attempt to download a file, all I get is an error. My code looks like the following.
$cordovaFileTransfer.download(url, path, {}, true)
.then(function(result) {
console.log(JSON.stringify(result));
}, function(err) {
console.log(JSON.stringify(err));
}, function(progress) {
console.log(JSON.stringify(progress));
});
这是错误(格式化)。
{
"code": 1,
"source": "http://192.168.0.169/api/user/file/e95cdcfd541746b3b0721c992d756137",
"target": "IMG_20160224_030826.jpg",
"http_status": 200,
"body": null,
"exception": "/IMG_20160224_030826.jpg: open failed: EROFS (Read-only file system)"
}
关于我在做什么的任何想法错误?如果 documentsDirectory
为空,我应该使用哪个 cordova.file。*
?
Any ideas on what I'm doing wrong? Which cordova.file.*
should I use if documentsDirectory
is null?
推荐答案
据我在cordova文件插件中检查,cordova.file.documentsDirectory对Android无效。
这是github中cordova文件插件官方文档中提到的描述:
As far as i checked in cordova file plugin, cordova.file.documentsDirectory is not valid for Android.
This is the description mentioned in cordova file plugin official documentation in github :
cordova.file.documentsDirectory - Files私有的应用程序,但这对其他应用程序(例如Office文件)有意义。请注意,对于OSX,这是用户的〜/ Documents目录。(iOS,OSX)
"cordova.file.documentsDirectory - Files private to the app, but that are meaningful to other application (e.g. Office files). Note that for OSX this is the user's ~/Documents directory. (iOS, OSX)"
试用适用于Android的cordova.file.externalDataDirectory或cordova.file.externalRootDirectory。希望它有所帮助
Try out cordova.file.externalDataDirectory or cordova.file.externalRootDirectory for Android. Hope it helps
这篇关于为什么cordova.file.documentsDirectory为null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!