用antd上传文件到oss,如果设置http头?

因为上传到oss上的文件,下载pdf格式的文件会默认打开,为了避免这个问题,需要将http头的Content-Disposition 设置为 attachment; 所以请问大神,如何在上传前,设置http头部信息。

阅读 4.8k
3 个回答

antd并不是很熟,应该是有上传之前执行的函数beforeupload(file)之类的函数。要说改http头的话,可以在这个函数里,替换掉封装好的file为函数获取到的file,这时候该文件的header就会改变成oss直接下载的-> Content-Type: application/octet-stream

昨天给你回答的你看了么???
oss里面去设置http头

可以借鉴一下这个 :
import { Upload, message, Button, Icon } from 'antd';

const props = {
name: 'file',
action: '//jsonplaceholder.typicode.com/posts/',
headers: {

authorization: 'authorization-text',

},
onChange(info) {

if (info.file.status !== 'uploading') {
  console.log(info.file, info.fileList);
}
if (info.file.status === 'done') {
  message.success(`${info.file.name} file uploaded successfully`);
} else if (info.file.status === 'error') {
  message.error(`${info.file.name} file upload failed.`);
}

},
};

ReactDOM.render(
<Upload {...props}>

<Button>
  <Icon type="upload" /> Click to Upload
</Button>

</Upload>,
mountNode);

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题