1***@qq.com
1***@qq.com
  • 发布:2022-05-16 00:44
  • 更新:2022-05-19 12:06
  • 阅读:413

uniCloud.uploadFile不能使用uni.canvasToTempFilePath返回的tempFilePath作为参数吗?

分类:uniCloud

downLoadImage(){
uni.canvasToTempFilePath({
x: 0,
y: 0,
width: this.canvasW,
height: this.canvasH,
destWidth: 375,
destHeight: 375,
canvasId: 'mycanvas1',
success: (res) => {
uniCloud.uploadFile({
filePath:res.tempFilePath,
cloudPath:'3.jpg'
})
}

     })  
   }  

如果使用uni.canvasToTempFilePath返回的tempFilePath作为参数的结果如图

2022-05-16 00:44 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

代码贴出来看看,你传的filePath是undefined

1***@qq.com

1***@qq.com (作者)

微信开发者工具是没有没问题,但是字节跳动开发者工具就报错了

  • DCloud_uniCloud_WYQ

    将uniCloud.uploadFile换成uni.uploadFile试试,上传地址改成https://httpbin.org/post

    2022-05-17 16:29

1***@qq.com

1***@qq.com (作者)

换成uni.uploadFile后,仍然报错了
downLoadImage(){
uni.canvasToTempFilePath({
x: 0,
y: 0,
width: this.canvasW,
height: this.canvasH,
destWidth: 375,
destHeight: 375,
canvasId: 'mycanvas1',
success: (res) => {
uni.uploadFile({
url:'https://httpbin.org/post',
filePath:res.tempFilePath,
name: 'file',
success: (res) => {
console.log(res);
},
fail: (res) => {
console.log(res);
}
})

          }  
      })  

     }
  • DCloud_uniCloud_WYQ

    看起来像是抖音开发工具的问题,你试试看真机运行有没有这种报错

    2022-05-19 16:33

  • 1***@qq.com (作者)

    回复 DCloud_uniCloud_WYQ: 用uniCloud.uploadFile()真机试调是没问题的,但在小程序模拟器就不行了。

    2022-05-19 21:12

  • 1***@qq.com (作者)

    我中间加了uni.downloadFile(),小程序模拟器就可以成功上传云存储了

    downLoadImage(){

    uni.canvasToTempFilePath({

    x: 0,

    y: 0,

    width: this.canvasW,

    height: this.canvasH,

    destWidth: 375,

    destHeight: 375,

    canvasId: 'mycanvas1',

    success: (res) => {

    uni.downloadFile({

    url:res.tempFilePath,

    success: (res) => {

    uniCloud.uploadFile({

    filePath:res.tempFilePath,

    cloudPath:'11.png',

    success: (res) => {

    console.log(res);

    },

    fail: (res) => {

    console.log(res);

    }

    })

    },

    fail: (res) => {

    console.log(res);

    }

    })

    }

    })


         }

    2022-05-19 21:13

  • 1***@qq.com (作者)

    回复 1***@qq.com: uni.canvasToTempFilePath()返回的临时地址是http开头的,而uni.downloadFile()返回的地址是ttfile开头的(在字节跳动小程序中)。

    2022-05-19 21:16

  • DCloud_uniCloud_WYQ

    回复 1***@qq.com: 那应该就是抖音开发工具的问题

    2022-05-20 10:55

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