Multipart.add_file_content_with_name (issue #69) #71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR extend Multipart functions with:
Multipart.add_file_content
Multipart.add_file_content_with_name
Those are a variation on
Multipart.add_file
and* Multipart.add_file_with_name
. They accept the file_content binary in place of file_path.Note
Multipart was strictly based on hackney multipart implementation and so the
{:multipart, multiparts}
request body form was fully compatible with:hackney.request
.With this extension we diverge from hackney breaking the request body compatibility.
This is the reason why I changed
Maxwell.Adapter.Hackney.send_multipart
callback to use aUtil.multipart_encode
.Another option is to open a PR to hackney in the same direct of this one.
In my opinion, given that only hackney natively support multipart body, it's better to use for all the adapter the Maxwell multipart encoder. It is consistent among all adapter library and easier to maintain.
If you agree with me, a further improvement could be refactoring out
send_multipart
callback from all the adapters and callUtil.multipart_encode
in adapter.excall
before passing down tosend_direct
(as I did in this PR for hackney). Let me know.