taro-微信小程序如何将url转成file文件对象

\\\\问题描述:后端需要file文件,而小程序拍照剪辑后得到的tempFilePath是临时链接,不是file文件对象。找遍了小程序的所有api都没有

本来想通过普通js写,但是小程序又不支持newImage。想看看大家有没有好的方法和案例

\#\#\# 如何将url转成file对象

\#\#\# 相关代码
Taro.canvasToTempFilePath({//调用方法,开始截取

            x: x,   
            y: ys,
            width: width,
            height: areaHeight,
            destWidth: destWidth,
            destHeight: areaHeight,
            canvasId: 'myCanvas',
            success: function (res) {
              Taro.showLoading({
                title: '成功',
              })
              imgFiles.push(res.tempFilePath)
              _this.setState({
                imgFiles
              })
              Taro.hideLoading()
              console.log('res.tempFilePath',i,ys,res.tempFilePath);
            }
          })
阅读 7.5k
1 个回答

wx.uploadFile 接口上传。

本质就是 FormData,小程序帮你做了封装,让你传个临时路径就行了,底层怎么转换成 FormData 的跟你无关。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题