touchphoto() {
const that = this
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
success(res) {
var tempFile = res.tempFiles
console.log(tempFile)
wx.compressImage({
src: tempFile[0].tempFilePath, // 图片路径
quality: 80, // 压缩质量,解决上传原图缓慢
success(result) {
console.log(result.tempFilePath)
wx.showLoading({
title: '系统处理中',
})
that.upLoadIdImg(result.tempFilePath)
},
fail(){
that.upLoadIdImg(tempFile[0].tempFilePath)
}
})
}
})
},
upLoadIdImg(tempFilePath) {
const that = this
wx.uploadFile({
// url: "xxxxx", //测试接口地址
filePath: tempFilePath,
name: '字段名',
formData: {
字段名: tempFilePath,
},
header: {
"Content-Type": "multipart/form-data",
'authToken': ""
},
success(res) {
wx.hideLoading()
res = JSON.parse(res.data)
console.log(res, '结果')
},
})
},
微信小程序上传图片,解决选择原图上传缓慢问题
最新推荐文章于 2024-09-30 20:17:19 发布