Using Postman I was able to upload the file to server , but when I use the same script in VSCode, error is thrown - read ECONNRESET error and CGI parser error
Code
const axios = require('axios');
import { readFileSync } from 'fs';
var formData = require('form-data');
var data = new formData();
data.append('file', readFileSync('path/to/file/to/upload'));
const body = {
file: data,
};
const headers = {
'Content-Type': 'multipart/form-data',
};
const url = 'http://localhost:8080/queryparameters';
async function abc() {
await axios
.post(url, body, { headers })
.then((data) => {
console.log(data);
})
.catch((e) => console.log(e));
}
abc();
Error message
- ECONNRESET
{
status: 200,
statusText: 'OK',
headers: {
date: 'Wed, 22 Nov 2022 04:54:19 GMT',
'content-type': 'text/html',
connection: 'close'
},
.
.
.
cause: Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
}
- CGI Parser
{
status: 200,
statusText: 'OK',
headers: AxiosHeaders {
date: 'Wed, 22 Nov 2022 06:34:21 GMT',
'content-type': 'text/html',
connection: 'close',
[Symbol(defaults)]: null
},
.
.
.
data: '<title>Error occurred.</title><h2>Error occurred.</h2>Error parsing CGI request: CgiParser: reached end of input while seeking end of headers or content. Format of CGI input is wrong\n'
Tried the following :
- adding content length
- with and without VPN connection
- also with urllib and fetch - got same error