Node.js axios upload large file using FormData, read all data to the memory, cause out of memory issue.
See original GitHub issueDescribe the bug
Node.js axios upload large file using FormData, read all data to the memory, cause out of memory issue.
To Reproduce
const formData = new FormData();
formData.append('file', fs.createReadStream(path), { filepath: path, filename: basename(path) });
formData.append('videoId', videoId);
await axios.post(UPLOAD_MEDIA_URL, formData, {
headers: {
'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,
'Authorization': `Bearer ${await token()}`,
},
maxBodyLength: Infinity,
maxContentLength: Infinity,
});
Expected behavior
Read file and upload by stream, without loading all data in the memory.
Environment
- Axios Version [0.21.1]
- Adapter [HTTP]
- Node.js Version [v14.16.0]
- OS: [Alpine in docker, OSX 10.15.6]
- Additional Library Versions [form-data@4.0.0]
Additional context/Screenshots
Not needed.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:10
Top Results From Across the Web
Unable to upload large files using nodejs/axios - Stack Overflow
I am using the following code to upload files, it works fine for files upto 2 gb, but beyond that it throws an...
Read more >Send a File With Axios in Node.js - Maxim Orlov
In this article, you'll learn how to send files and associated data by constructing a form. We'll cover the two file types —...
Read more >A complete guide to CSV files in Node.js - LogRocket Blog
In this article, we will learn how to manage CSV files in Node. ... in the above examples, Node will read the entire...
Read more >Spring Boot File upload example with Multipart File - BezKoder
In this tutorial, I will show you how to upload and download files with a Spring Boot Rest APIs to/from a static folder....
Read more >S3 direct file upload using presigned URL from React and Rails
const { url, file_key: fileKey, s3_upload_params: fields } = uploadParams; const formData = new FormData(); formData.append('Content-Type', ' ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just give a clue for it, after I add the
maxRedirects: 0
option, the upload will use much less memory than before.maxRedirects: 0
will switch the transport fromhttp/https
tofollow-redirects
, it seemsfollow-redirects
use much more memory when uploading big file. Hope anyone can optimize this problem, thanks.Facing this issue myself. Asked a question here: https://stackoverflow.com/questions/73679209/submitting-form-data-via-axios-fails-with-datasize-0