钉钉小程序文件上传 报无效参数

钉钉小程序文件上传 报无效参数

在这里插入图片描述

原因为没有加fileType,文档中居然为非必填

// 多文件上传
export function mutiUpload(tempFilePaths) {
  return Promise.all(
    tempFilePaths.map((file, index) => {
      return new Promise((resolve, reject) => {
        console.log(file);

        dd.uploadFile({
          url: BASE_API,
          filePath: file,
          fileName: "file",
          fileType: "image",	// 不加fileType就报参数无效
          header: getCommonHeader(),
          success(res) {
            console.log("上传文件成功!", res);
            resolve(res);
          },
          fail(err) {
            console.log("上传文件失败!!!!!", err);
            dd.alert({
              title: "文件上传失败!",
              duration: 1000
            });
            reject(err);
          }
        });
      });
    })
  );
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uni.request({ url: config.baseUrl + '/API/Task/getToken', method: 'GET', success(res) { that.baseUrl = res.data.domain that.token = res.data.token; // 获取到 token 后再进行上传 that.imgList.push(e.tempFilePaths[0]); const fileName = e.tempFilePaths[0].substr(e.tempFilePaths[0] .lastIndexOf('/') + 1); // 获取文件名 const fileExt = fileName.substr(fileName.lastIndexOf('.') + 1) .toLowerCase(); // 获取文件拓展名,并转换为小写 const today = new Date().toISOString().slice(0, 10); // 获取当天日期,格式为 yyyy-mm-dd const now = new Date(); const year = now.getFullYear(); const month = now.getMonth() + 1; const day = now.getDate(); const hour = now.getHours(); const minute = now.getMinutes(); const currentDateTime = ${year}-${month}-${day}-${hour}:${minute}:00; var nums = []; that.uploadCount++; // 上传次数加一 const newFileName = currentDateTime + '' + that.uploadCount + '.' + fileExt; // 生成新的文件名,以上传次数为前缀 const path = that.fromData.c_name + '/' + that.fromData.a_name + '/' + that.fromData.m_name + '/' + that.fromData.mold + '/' + that.fromData.m_title + '/' + that.fromData.r_name + '-' + that.uploadCount + '/' + that.fromData.o_name + '/' + today; const key = path + '/' + newFileName that.imgData.push(key) uni.uploadFile({ url: 'https://upload-z1.qiniup.com', filePath: e.tempFilePaths[0], name: 'file', formData: { token: res.data.token, key: path + '/' + newFileName // 将路径和文件名拼接起来 }, success(res) { const data = JSON.parse(res.data); const key = data.key const parts = key.split("."); const KeynewName = parts.slice(0, -1).join(".") + ".jpg"; that.baseList.push(that.baseUrl + KeynewName) that.Keyname.push(KeynewName) for (var i = 0; i < that.Keyname.length; i++) { var num = that.Keyname[i].split('/').slice(-1)[0].split('.')[0].split('')[1]; nums.push(num); } console.log('存在的文件名:'+nums) }, fail(erro) { console.log(erro); } }); }, fail(err) { console.log("获取 Token 失败:", err); } });我想让这里的uploadCount先判断nums中存在哪些,uploadCount只能为1,2,3 如果nums存在1,2那么uploadCount只能为3
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值