阿里云oss上传 ---前端
uni.chooseImage({count:1,sizetype:['compressed'],success(res){varimgFilesObj=res.tempFiles[0];that.userPhoto=imgFilesObj.path;...
·
uni.chooseImage({
count: 1,
sizetype: ['compressed'],
success(res) {
var imgFilesObj = res.tempFiles[0];
that.userPhoto = imgFilesObj.path;
uni.showLoading({
title: '上传中',
mask: true
});
// 做成一个上传对象
uni.uploadFile({
// 需要上传的地址
url: that.$baseSingerUrl,
// filePath 需要上传的文件
filePath: imgFilesObj.path,
name: 'file',
formData: {
dirName: 'cfjfb'
},
success(resImg) {
console.log(resImg)
let oGetTime = new Date().getTime()
let ossObj = JSON.parse(resImg.data)
let ossObjs = JSON.parse(ossObj);
uni.uploadFile({
url: ossObjs.host, //仅为示例,非真实的接口地址
filePath: imgFilesObj.path,
name: 'file',
formData: {
OSSAccessKeyId: ossObjs.OSSAccessKeyId,
accessKey: ossObjs.accessKey,
bucket: ossObjs.bucket,
expire: ossObjs.expire,
host: ossObjs.host,
key: ossObjs.key + '/' + oGetTime,
policy: ossObjs.policy,
signature: ossObjs.signature,
type: res.tempFiles[0].type,
name: res.tempFiles[0].name,
lastModifiedDate: res.tempFiles[0].lastModifiedDate,
size: res.tempFiles[0].size
},
success: (uploadFileRes) => {
that.userPhotoArr = [];
that.userPhotoArr.push({
url: ossObjs.key+'/'+oGetTime,
sId: oGetTime,
name: imgFilesObj.name
});
updateUserInfoApi({
photo: JSON.stringify(that.userPhotoArr)
}).then(user=>{
uni.setStorageSync('userInfo', user.data)
});
}
});
}
});
}
});
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)