You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
920 B

import functions from "./functions.js";
// 用于下载图片之类封装的网络请求 用于可以选择本地相册和一个允许摄像机拍照
const apiUrl = `${functions.getDomain()}/api/upload`;
export default function() {
return new Promise((relove, reject) => {
// 从本地相册选择图片或使用相机拍照
uni.chooseImage({
count: 1, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', "camera"], //从相册选择
success: function(res) {
let path = res.tempFilePaths[0];
uni.uploadFile({
url: apiUrl,
filePath: path,
name: 'file',
formData: {},
success: (uploadFileRes) => {
let res = JSON.parse(uploadFileRes.data);
if (res.code == 200) {
relove(res.data);
} else {
functions.error(res.msg);
}
}
});
}
});
})
}