赞
踩
HTML部分
<el-upload
class="avatar-uploader"
action="123"
:http-request="upload"
:before-upload="beforeAvatarUpload">
<img v-if="params.defaultImgUrl" :src="params.defaultImgUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
js 部分
upload(res) { let file = res.file; //注意:直接上传file文件,不要用FormData对象的形式传 let config = { headers: { 'Content-Type': 'multipart/form-data' } }; //从接口获取presigned url getUploadUrl({uploadType: 6}).then(res => { let result = res.data; if (result.code === 0) { const info = JSON.parse(result.msg); //需要用put方法上传,post会报405,aws官方规定是put方法 axios.put(info.presignedUrl, file, config) .then(res => { if (res.status == 200) { this.params.defaultImgUrl = info.cdnUrl; } }).catch( err => { console.log(err) } ) } }).catch(err => { console.log('get upload info', err) }) }
附上参考的解决方案github地址:
https://github.com/aws/aws-sdk-js/issues/547
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。