uni-app 钉钉小程序鸿蒙next真机相册图片上传无反应

uni-app 钉钉小程序鸿蒙next真机相册图片上传无反应

类别 信息
产品分类 uniapp/小程序/钉钉
开发环境 Mac
版本号 sonoma 14.7.4 (23H420)
HBuilderX 正式版
HBuilderX版本号 4.66
第三方开发者工具版本号 3.9.41 (3.9.41)
基础库版本号 vue 2
项目创建方式 HBuilderX

操作步骤:

chooseImage(){ uni.chooseImage({ count: 1, sizeType: [‘compressed’], success: (res)=>{ console.log(JSON.stringify(res)); let fileName = “”; let filePath = “”; uni.showModal({ title:“图片选择成功”, content: JSON.stringify(res), success: () => {}, fail: () => {}, }); if(res.tempFilePaths){ console.log(res.tempFilePaths[0]); filePath = res.tempFilePaths[0]; fileName = filePath.substring(filePath.lastIndexOf("/")+1); } else if(res.files){ console.log(res.files[0].path); filePath = res.files[0].path; fileName = filePath.substring(filePath.lastIndexOf("/")+1); } this.uploadFile(filePath, fileName); }, fail:(err)=>{ console.log(JSON.stringify(err)); } }); }, uploadFile(filePath, fileName){ uni.showModal({ title:“图片信息”, content: “路径:” + filePath + “===” + “名称:” + fileName, success: () => {}, fail: () => {}, }); uni.showLoading({ title:“上传中…” }); uni.uploadFile({ url: ‘https://up-z0.qiniup.com’, header: { “content-type”:‘multipart/form-data’ }, filePath: filePath, fileType: ‘image’, name: ‘file’, timeout: 30000, formData: { ‘key’: fileName, ‘token’: this.upLoadToken, }, success: (result) =>{ console.log(“success=>”+JSON.stringify(result)); if(result.statusCode===200){ this.imageList.push(this.upLoadPath+"/"+(JSON.parse(result.data)).key); if(this.imageList.length>=4&&this.imageList.indexOf(“添加”)!==-1){ this.imageList = this.imageList.filter(v=>{ return v!==“添加”; }); } } }, fail:(err)=>{ console.log(“fail=>”+JSON.stringify(err)); }, complete:(data)=>{ uni.hideLoading(); console.log(“complete=>”+JSON.stringify(data)); } }); },


### 预期结果:


chooseImage(){
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
success: (res)=>{
console.log(JSON.stringify(res));
let fileName = "";
let filePath = "";
uni.showModal({
title:"图片选择成功",
content: JSON.stringify(res),
success: () => {},
fail: () => {},
});
if(res.tempFilePaths){
console.log(res.tempFilePaths[0]);
filePath = res.tempFilePaths[0];
fileName = filePath.substring(filePath.lastIndexOf("/")+1);
} else if(res.files){
console.log(res.files[0].path);
filePath = res.files[0].path;
fileName = filePath.substring(filePath.lastIndexOf("/")+1);
}
this.uploadFile(filePath, fileName);
},
fail:(err)=>{
console.log(JSON.stringify(err));
}
});
},
uploadFile(filePath, fileName){
uni.showModal({
title:"图片信息",
content: "路径:" + filePath + "===" + "名称:" + fileName,
success: () => {},
fail: () => {},
});
uni.showLoading({
title:"上传中..."
});
uni.uploadFile({
url: 'https://up-z0.qiniup.com',
header: {
"content-type":'multipart/form-data'
},
filePath: filePath,
fileType: 'image',
name: 'file',
timeout: 30000,
formData: {
'key': fileName,
'token': this.upLoadToken,
},
success: (result) =>{
console.log("success=>"+JSON.stringify(result));
if(result.statusCode===200){
this.imageList.push(this.upLoadPath+"/"+(JSON.parse(result.data)).key);
if(this.imageList.length>=4&&this.imageList.indexOf("添加")!==-1){
this.imageList = this.imageList.filter(v=>{
return v!=="添加";
});
}
}
},
fail:(err)=>{
console.log("fail=>"+JSON.stringify(err));
},
complete:(data)=>{
uni.hideLoading();
console.log("complete=>"+JSON.stringify(data));
}
});
},

实际结果:

chooseImage(){ uni.chooseImage({ count: 1, sizeType: [‘compressed’], success: (res)=>{ console.log(JSON.stringify(res)); let fileName = “”; let filePath = “”; uni.showModal({ title:“图片选择成功”, content: JSON.stringify(res), success: () => {}, fail: () => {}, }); if(res.tempFilePaths){ console.log(res.tempFilePaths[0]); filePath = res.tempFilePaths[0]; fileName = filePath.substring(filePath.lastIndexOf("/")+1); } else if(res.files){ console.log(res.files[0].path); filePath = res.files[0].path; fileName = filePath.substring(filePath.lastIndexOf("/")+1); } this.uploadFile(filePath, fileName); }, fail:(err)=>{ console.log(JSON.stringify(err)); } }); }, uploadFile(filePath, fileName){ uni.showModal({ title:“图片信息”, content: “路径:” + filePath + “===” + “名称:” + fileName, success: () => {}, fail: () => {}, }); uni.showLoading({ title:“上传中…” }); uni.uploadFile({ url: ‘https://up-z0.qiniup.com’, header: { “content-type”:‘multipart/form-data’ }, filePath: filePath, fileType: ‘image’, name: ‘file’, timeout: 30000, formData: { ‘key’: fileName, ‘token’: this.upLoadToken, }, success: (result) =>{ console.log(“success=>”+JSON.stringify(result)); if(result.statusCode===200){ this.imageList.push(this.upLoadPath+"/"+(JSON.parse(result.data)).key); if(this.imageList.length>=4&&this.imageList.indexOf(“添加”)!==-1){ this.imageList = this.imageList.filter(v=>{ return v!==“添加”; }); } } }, fail:(err)=>{ console.log(“fail=>”+JSON.stringify(err)); }, complete:(data)=>{ uni.hideLoading(); console.log(“complete=>”+JSON.stringify(data)); } }); },


### bug描述:


uni-app uni.chooseImage方法实现后,调用uni.uploadFile方法,在鸿蒙next真机无反应,安卓真机和苹果真机正常;在鸿蒙next真机测试过程中uni.chooseImage方法实现返回函数,无tempFilePaths值或者tempFiles返回参数,安卓真机和苹果真机正常;

更多关于uni-app 钉钉小程序鸿蒙next真机相册图片上传无反应的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

你试试原生钉钉小程序有无此问题,如果有问题,可以反馈到钉钉小程序社区;没有麻烦发个可复现demo。

更多关于uni-app 钉钉小程序鸿蒙next真机相册图片上传无反应的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


我先反馈一下,钉钉原生也是一样的情况

根据你描述的问题,这是鸿蒙Next系统在uni-app钉钉小程序中的兼容性问题。主要问题出现在uni.chooseImage方法的返回值处理上。

在鸿蒙Next真机中,uni.chooseImage返回的数据结构可能与其他平台不同。你当前的代码只处理了tempFilePathsfiles两种格式,但鸿蒙Next可能返回了其他格式。

建议修改chooseImage方法中的路径获取逻辑:

chooseImage(){
  uni.chooseImage({
    count: 1,
    sizeType: ['compressed'],
    success: (res) => {
      console.log('chooseImage返回:', JSON.stringify(res));
      
      let filePath = '';
      
      // 兼容性处理:依次检查可能的路径字段
      if(res.tempFilePaths && res.tempFilePaths.length > 0){
        filePath = res.tempFilePaths[0];
      } else if(res.tempFiles && res.tempFiles.length > 0){
        filePath = res.tempFiles[0].path;
      } else if(res.files && res.files.length > 0){
        filePath = res.files[0].path;
      } else {
        // 如果以上都不存在,直接使用res对象中的第一个可用路径
        for(let key in res){
          if(typeof res[key] === 'string' && res[key].startsWith('http')){
            filePath = res[key];
            break;
          }
        }
      }
      
      if(!filePath){
        uni.showToast({title: '获取图片路径失败', icon: 'none'});
        return;
      }
      
      const fileName = filePath.substring(filePath.lastIndexOf("/")+1);
      this.uploadFile(filePath, fileName);
    },
    fail:(err)=>{
      console.log('选择图片失败:', JSON.stringify(err));
      uni.showToast({title: '选择图片失败', icon: 'none'});
    }
  });
}
回到顶部