#upload files formdata

25 messages · Page 1 of 1 (latest)

uncut hollow
#

How can I upload files with multipart/form-data using fetch?

raw thicket
#

||You can always type the same in google, you’ll get an answer 100%||

uncut hollow
raw thicket
uncut hollow
#

What if I want to send more files at once though. 🤔

#

should be possible somehow

slow coral
#

more files in the same form field?

#

what does the server expect?

uncut hollow
slow coral
#

oh, then I guess

formData.append("files", file1);
formData.append("files", file2);
short canyon
#

You need to encode them into a Blob. And I believe filesystem based blobs are not yet supported, tho I can't find an issue.

#

Not aware of any modern FormData library that accepts strings either

slow coral
#

filesystem based blobs are not supported, but you can read the files into memory

#

that's only an issue if the files are huge

short canyon
#

Where's the issue for filesystem based Blobs?

uncut hollow
#

For my use case it will just be long strings converted to Blobs so I should be fine with that.

slow coral
#

if the server is expecting files, they might need a filename and a mime type

#

but if you're building the blobs yourself, ok

short canyon
#

File requires a name and has optional mime type

slow coral
#

well, if you don't specify the mime type it gets set to the empty string

#

because multipart/form-data file fields must have a mime type header

#

but anyway

uncut hollow
#

got it to work. Thanks for the help 👍