1787624543
1787624543
  • 发布:2021-09-16 10:16
  • 更新:2021-09-16 10:16
  • 阅读:568

#插件讨论# 【 图片 视频上传 预览 【简单好上手】 - 灰兔子 】如果出现拍照返回的路径无效可以按照我下面的方法解决

分类:uni-app

把插件里面的 appCamera() 这个方法替换成

appCamera() {
var cmr = plus.camera.getCamera();
var res = cmr.supportedImageResolutions[0];
var fmt = cmr.supportedImageFormats[0];
let that = this;
//console.log("Resolution: " + res + ", Format: " + fmt);
cmr.captureImage((path) => {
//alert("Capture image success: " + path);
plus.io.resolveLocalFileSystemURL(path, function(entry) {
console.log(entry.toLocalURL())
that.compressImage(entry.toLocalURL(),entry.name);
}, function(e) {
plus.nativeUI.toast("读取拍照文件错误:" + e.message);
});
},
(error) => {
//alert("Capture image failed: " + error.message);
console.log("Capture image failed: " + error.message)
}, {
resolution: res,
format: fmt
}
);
},
compressImage(url,filename){
var name="_doc/upload/"+filename;
let that = this;
uni.compressImage({
src:url,//src: (String 类型 )压缩转换原始图片的路径
dst:name,//压缩转换目标图片的路径
overwrite:true,//overwrite: (Boolean 类型 )覆盖生成新文件
success: res => {
this.chooseSuccessMethod([res.tempFilePath], 0)
},
fail: (err) => {
//console.log(err.errMsg);
console.log("Capture image failed: " + err)
},
complete: () => {
//uni.hideLoading();
}
})
},
增加了一个compressImage(url,filename) 方法用来处理路径无效问题

2021-09-16 10:16 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复