尝试使用 cordova-plugin-camera 通过android / ios Gallery从离子应用程序上传图像。 它在ios上运行正常,但在解析路径时抛出错误,我正在使用 cordova-plugin-filepath 来解析文件路径。
但是在 this.filePath.resolveNativePath(imagePath) 方法中解析本机路径时,它总是引发以下错误:
{code: 0 ; message: "Unable to resolve filesystem path."}
这是我上传图片的代码:
var options = {
quality: 60,
targetWidth:900,
sourceType: sourceType,
saveToPhotoAlbum: false,
correctOrientation: true
};
// Get the data of an image
this.camera.getPicture(options).then((imagePath) => {
if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
console.log('image path',imagePath)
this.filePath.resolveNativePath(imagePath)
.then(res => {
let correctPath = res.substr(0, res.lastIndexOf('/') + 1).toString();
let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.length).toString();
this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
}).catch(err=>{
console.log('unable to resolve file path issue', err)
});
} else {
var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
console.log(currentName,correctPath)
this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
}
}, (err) => {
console.log(err);
});
我什至尝试使用以下代码,但没有成功:
window.FilePath.resolveNativePath(imagePath)
.then(res => {
let correctPath = res.substr(0, res.lastIndexOf('/') + 1).toString();
let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.length).toString();
this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
}).catch(err=>{
console.log('unable to resolve file path issue', err)
});
这是我的插件详细信息:
<plugin name="cordova-plugin-camera" spec="^4.0.3" />
<plugin name="cordova-plugin-filepath" spec="^1.4.2" />
离子信息:
ionic (Ionic CLI) : 4.6.0
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.1
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : android 7.1.4
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.3.1, (and 15 other plugins)
System:
Android SDK Tools : 25.2.4
NodeJS : v9.11.1
npm : 6.0.1
OS : Windows 10"