阅读背景:

uni-app 文件上传oss

来源:互联网 
changeUserPhoto() { let that = this; uni.chooseImage({ count: 1, sizetype: ['compressed'], success(res) { var imgFilesObj = res.tempFiles[0]; that.userPhoto = imgFilesObj.path; uni.showLoading({ title: '上传中', mask: true }); // 做成一个上传对象 var uper = uni.uploadFile({ // 需要上传的地址 url: 文件上传地址, // filePath 需要上传的文件 filePath: imgFilesObj.path, name: 'file', formData: { dirName: 'cfjfb' }, success(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) }); } }); } }); } }); }, changeUserPhoto() { let that = this; uni.chooseIm



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: