The Problem
I've been trying to set the size
parameter in the content-disposition header for quite some time.
function uploadFile(file) {
const data = new FormData();
data.append('file', file);
axios.post('url/of/endpoint', data);
FormData does not send the size parameter by default and, to my knowledge, I can't see a way of setting it myself. Is there a way of doing this with Axios? Do I need to go more lower level and build my own headers?
The Context
My primary objective is to pipe a file input stream via a Java endpoint to S3. But without the file size, all of the data gets loaded into memory and has a high chance of causing an OOM exception. This specific problem has been asked here as well. Is writing my own byte buffer the only way? Should I just stop being lazy and do that? Seems like an overly-complex solution...
Is there a reason as to why the file size isn't normally included in FormData? I've tried using Content-Length, but that includes the content-disposition header and leads to a mismatched byte count.