uni.chooseImage({
count: 1, //默认9
sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album','camera'], //从相册选择,和摄像头功能,默认二者都有
success: res=> {
/*res.tempFilePaths[0]是获取到的第一个数据的blob地址,将他赋值给数据区的imgUrl*/
let imagePaths=res.tempFilePaths[0]
uni.uploadFile({
// 需要上传的地址
url:‘上传的地址’,
method: 'POST',
header: {
'Authorization':'Bearer ' + ****
},
// filePath 需要上传的文件
filePath: imagePaths,
name: 'photofile',
success(res1) {
// 显示上传信息
console.log(res1)
let aaa = JSON.parse(res1.data)
let bbb = JSON.parse(res1.statusCode)
if(bbb==200){
}else{
uni.showModal({
title: '提示',
content: '上传失败',
success(res) {
let that = this
if (res.confirm) {
} else if (res.cancel) {
}
}
});
}
}
});
}
});
uniapp图片上传
于 2022-06-09 16:03:02 首次发布