Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

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);
            }
          })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

wx.uploadFile 接口上传。

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...