chooseImg(type) {
this.type = type
let that = this
uni.chooseImage({
count: 1, //默认9
success: function (res) {
uni.showLoading({ title: '图片上传中', mask: true })
that.files = res.tempFiles[0].path.split('.')//将图片地址用.分割成数组
const name = that.files[that.files.length-1]//取数组中的最后一个为上传的文件名后缀
that.urlTobase64(res.tempFilePaths[0],name);
}
});
},
//图片转base64
async urlTobase64(url,name) {
let base64 = uni.getFileSystemManager().readFileSync(url, "base64") //图片转base64的方法
const res = await uploadFile({assetContent:base64,assetName:`file.${name}`})//上传图片接口
uni.hideLoading()
uni.showToast({title:'上传成功',duration:2000,icon:'none'})
//type为1,上传的是身份证的正面
if(this.type===1){
this.cardFrontPath = url
}else{
this.cardBackPath = url
}
},
uniapp上传图片转base64
最新推荐文章于 2024-08-19 20:22:19 发布