uniapp-上传图片
# uni.uploadFile(OBJECT)
uni.chooseImage({
success: (chooseImageRes) => {
const tempFilePaths = chooseImageRes.tempFilePaths;
uni.uploadFile({
url: 'https://www.example.com/upload', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],//图片路径
name: 'file',//发请求给后端,图片所对应的key值
formData: {
'user': 'test'//除图片以外其他数据
},
success: (uploadFileRes) => {
console.log(uploadFileRes.data);//成功的响应
}
});
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
上次更新: 2024/08/14, 04:14:33