uni.chooseImage(OBJECT):從本地相冊選擇圖片或使用相機拍照。
uni.uploadFile(OBJECT):將本地資源上傳到開發者服務器,客戶端發起一個 POST 請求,其中 content-type 為 multipart/form-data。
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'], //可以指定是原圖還是壓縮圖,默認二者都有
sourceType: ['album'], //從相冊選擇
success: res => {
console.log(res);
uni.uploadFile({
url: ' http://upload.qiniup.com/',
filePath: this.filePath.concat(res.tempFilePaths).toString(),
name: 'file',
formData: {
key: Math.round(new Date() / 1000),
token: this.token
},
success: result => {
this.producImg = res.tempFiles[0].path;
console.log(result.data.key);
this.httpImg = 'http://' + this.http + '/' + Math.round(new Date() / 1000);
}
});
},
fail() {
uni.showToast({
title: 'chooseImage fail',
duration: 3000,
icon: 'none'
});
},
error: e => {
console.log(e);
}
});
