收藏
回答

wx.uploadFile 七牛直传 苹果手机上传失败?

uploadFile(file,token,key) {
    let that = this
    // 文件直传
    const uploadTask = wx.uploadFile({
      //https://up-z2.qiniup.com
      url: `https://up-z2.qiniup.com‌`,  // 视空间地域而定
      filePath: file,
      name: 'file',
      formData: {
        key: key,
        token: token, // 上传密钥
      },
      success(res) {
        const data = JSON.parse(res.data);
        const imgSrc = that.data.domain + data.key
        that.updateUser(data.key)
        console.log('上传成功',data);  // 返回文件哈希(hash)和云端文件名(key)
      },
      fail(err) {
        console.log('上传失败',err)
        // 上传失败处理
      }
    })
    // 上传进度回调
    uploadTask.onProgressUpdate((res) => {
      if(res.progress < 100){
        // 进度不足100时显示进度
        wx.showLoading({
          title: `上传中 ${res.progress}%`,
        });
      } else if (res.progress == 100){
        // 进度达到100时显示结果
        wx.showToast({
          title: '完成',
          icon: 'success'
        });
      }
    })
  },


回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 该问答由AI生成
    01-13
    有用
登录 后发表内容