uni-app上传图片(七牛云,app)

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);
}
});

猜你喜欢

转载自www.cnblogs.com/talust/p/12916478.html