2

Day 13/100 Ant Design 上传文件如何加token?

 2 years ago
source link: https://segmentfault.com/a/1190000041099548
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

今儿遇到了带宽上传文件的攻击(每秒150M+),导致了服务宕机1.5h。排查发现,上传文件没有token的参数。

上传组件添加token

2、为什么要添加token?

1)因为可以阻拦非平台请求;

2)平台内请求如果异常,可以禁用那个用户;

3、添加组件headers参数

1)页面组件
<a-upload-dragger
  v-model:fileList="file"
  name="file"
  :action="apiLink"
  :beforeUpload="beforeUploadFile"
  :headers="requestHeaders"
  @change="handleChange"
>
  <p class="ant-upload-drag-icon">
    <inbox-outlined></inbox-outlined>
  </p>
  <p class="ant-upload-text">
    点击或拖拽到区域上传
  </p>
</a-upload-dragger>
2)header 传 token
data(){
    requestHeaders: {
      Authorization: 'Bearer ' + token //页面token
    },
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK