Use antd to upload files to oss, if you set the http header?

because files uploaded to oss, downloading files in pdf format will be opened by default. In order to avoid this problem, you need to set the Content-Disposition of the http header to attachment;, so ask the god how to set the http header information before uploading.

Aug.06,2021

antd is not very familiar. It should be a function such as beforeupload (file), which is executed before upload. To change the http header, you can replace the encapsulated file as the file, obtained by the function in this function. Then the header of the file will be changed to be downloaded directly by oss-> Content-Type: application/octet-stream


did you see the answer given to you yesterday?
set the http header in oss


you can learn from this:
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);

Menu