axios / axios

Promise based HTTP client for the browser and node.js
https://axios-http.com
MIT License
105.13k stars 10.82k forks source link

axios uploads files through forms without boundary #6121

Open yimuyangshu opened 9 months ago

yimuyangshu commented 9 months ago

Describe the bug

When I used axios to upload a file to the server as a form, the content of the Content-type I manually set appeared without a semicolon in my actual request headers

To Reproduce

No response

Code snippet

try {
                        const data = fs.readFileSync(path);
                        const uint8Array = new Uint8Array(data);
                        let blob = new Blob([uint8Array],{type:'text/plain'});

                        const formData = new FormData();
                        formData.append('file', blob, "1.txt");

                        const config = {
                            headers: {
                                "Content-Type": 'multipart/form-data; boundary=77f77c04-2c7b-4179-aca3-my-cool-boundary'
                            }
                        }

                        const response = axios.post('url',formData,config);
                        console.log('success:', response);
                    } catch (error) {
                        console.error('error:', error);
                    }

Expected behavior

expected effect: multipart/form-data;boundary=77f77c04-2c7b-4179-aca3-my-cool-boundary

real effect: multipart/form-data boundary=77f77c04-2c7b-4179-aca3-my-cool-boundary

Axios Version

1.6.0

Adapter Version

No response

Browser

Chorme

Browser Version

119.0.6

Node.js Version

16.19.0

OS

window 10

Additional Library Versions

No response

Additional context/Screenshots

Request Headers:

Accept:
application/json, text/plain, */*
Accept-Encoding:
gzip, deflate, br
Accept-Language:
zh-CN
Connection:
keep-alive
Content-Length:
197
Content-Type:
multipart/form-data boundary=77f77c04-2c7b-4179-aca3-my-cool-boundary
Host:
127.0.0.1:10012
Sec-Ch-Ua:
"Not=A?Brand";v="99", "Chromium";v="118"
Sec-Ch-Ua-Mobile:
?0
Sec-Ch-Ua-Platform:
"Windows"
Sec-Fetch-Dest:
empty
Sec-Fetch-Mode:
cors
Sec-Fetch-Site:
cross-site
User-Agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) all_pass_tcq/1.0.0 Chrome/118.0.5993.89 Electron/27.0.2 Safari/537.36
yimuyangshu commented 9 months ago

I tried not to write the header information manually, but then he would remind me that the boundary was irregular