【发布时间】:2020-12-28 02:20:20
【问题描述】:
我在尝试使用 Cordova Camera Plugin 和 cordova-plugin-advanced-http 将视频文件上传到服务器时遇到了一些困难。从图库中上传 图像 时,该代码的作用就像一个魅力,但无论我做什么,从图库中上传 视频 时我总是会收到 EACCES (Permission denied):
file url -> file:///storage/emulated/0/DCIM/Camera/VID_20200908_114957.mp4
post-post-module-es2015.js:240 {status: -1, error: "There was an error with the request: /storage/emulated/0/DCIM/Camera/VID_20200908_114957.mp4: open failed: EACCES (Permission denied)"
只看错误信息,我们可以断定这是一个权限问题,所以我尝试使用cordova-plugin-android-permissions 并请求 READ_EXTERNAL_STORAGE 权限。不成功,应用有权限但错误依旧。
这是用于上传的部分代码
private chooseContentUsingCameraPlugin(SOURCE: number) {
const options: CameraOptions = {
destinationType: this.camera.DestinationType.FILE_URI,
mediaType: this.camera.MediaType.ALLMEDIA,
sourceType: SOURCE
};
this.camera.getPicture(options).then((contentUrl: string) => {
if (contentUrl.indexOf('://') === -1)
contentUrl = 'file://' + contentUrl;
const queryIndex = contentUrl.lastIndexOf('?');
if (queryIndex !== -1)
contentUrl = contentUrl.substring(0, queryIndex);
console.log('file url -> ', contentUrl);
this.startUpload(contentUrl);
}, (err) => this.onUploadError(err));
}
private startUpload(fileUrl){
...
this.nativeHttp.uploadFile(req.url, null, headers, fileUrl, fileName).then(res => {
let data = res.data;
if (res.data && (req.responseType === undefined || req.responseType === 'json'))
data = JSON.parse(res.data);
console.log(data)
}).catch(error => {
console.log(error)
});
}
有人可以解释导致此问题的原因吗?
【问题讨论】:
标签: android cordova ionic-framework cordova-plugins