因为上传到oss上的文件,下载pdf格式的文件会默认打开,为了避免这个问题,需要将http头的Content-Disposition 设置为 attachment; 所以请问大神,如何在上传前,设置http头部信息。
因为上传到oss上的文件,下载pdf格式的文件会默认打开,为了避免这个问题,需要将http头的Content-Disposition 设置为 attachment; 所以请问大神,如何在上传前,设置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);
10 回答11.2k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
antd并不是很熟,应该是有上传之前执行的函数beforeupload(file)之类的函数。要说改http头的话,可以在这个函数里,替换掉封装好的file为函数获取到的file,这时候该文件的header就会改变成oss直接下载的-> Content-Type: application/octet-stream