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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM