赞
踩
记录:
1.注意设置请求头的格式:
headers: {
'Content-Type': 'multipart/form-data'
},
如果不设置,上传接口返回成功,但是下载链接打不开
2.添加onUploadProgress方法,监控上传进度,方便进度条百分比的展示
AWS S3,JS 文档地址:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html
完整代码:
- import axios from 'axios'
-
- axios.put(presignUrl, fileList[0], {
- headers: {
- 'Content-Type': 'multipart/form-data'
- },
- onUploadProgress: progressEvent => {
- let complete = (progressEvent.loaded / progressEvent.total * 100.).toFixed(2)
-
- }
- })
- .then((res: any) => {
- if (res.status == 200) {
- console.log(res)
- }
- }).catch(
- err => {
- console.log(err)
- })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。