benoitc / hackney

simple HTTP client in Erlang
Other
1.34k stars 427 forks source link

Need a way to set filename for Content-Disposition when uploading file-data from memory #702

Open DHager opened 2 years ago

DHager commented 2 years ago

I ran into an issue where a remote server would refuse data (inside a multipart) unless the Content-Disposition header contained a filename, but I couldn't find any way to set one.

To be specific, in a multipart-part the server required:

Content-Disposition: form-data; name="data_form_input_name"; filename="original_filename.dat"

But refused to accept:

Content-Disposition: form-data; name="data_form_input_name"

I looked at the documentation for encode_form/1 but I wasn't able to solve the issue with ExtraHeaders, because the goal is to modify the existing header, rather than adding new siblings.

DHager commented 2 years ago

My current workaround is to save the data to a temporary file on disk (with a specific name), use {file, Path, Name, ExtraHeaders}, and then delete the temporary file afterwards... But it's annoying.

benoitc commented 2 years ago

we can have a pattern that just place needed headers instead. I will think about it

DHager commented 2 years ago

Hi, any updates on this?

One option may be to add a new item to the list, {file_in_memory, Name, FileName, Data, ExtraHeaders}.

This is in contrast to {file, Path, Name, ExtraHeaders}, where the Path is indirectly supplying both FileName and Data through a disk-access.

DHager commented 1 year ago

Ping.