How to post multipart form data? #160
-
Trying to make a request that posts multipart form data including a file. The file comes from an external URL, and currently we're downloading the file to memory and then posting that though not sure that's the most efficient way. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Here is an example of how to post the data directly: https://github.com/socketry/async-rest/blob/ae3d6da90d6fa8383304bfc66d334954e857dcb2/lib/async/rest/wrapper/form.rb#L27-L33 Regarding files, you'll need to construct a multipart body. Actually, there isn't a good mechanism for this but this might be a good start: https://github.com/socketry/multipart-post/blob/2b1235a25bc3ff03d907785caa83f09c69d6f501/lib/multipart/post/multipartable.rb Doing it in-memory is okay if you have enough memory/swap to do so. Beyond that, what we should probably introduce is |
Beta Was this translation helpful? Give feedback.
-
@ioquatix how do you see |
Beta Was this translation helpful? Give feedback.
Here is an example of how to post the data directly: https://github.com/socketry/async-rest/blob/ae3d6da90d6fa8383304bfc66d334954e857dcb2/lib/async/rest/wrapper/form.rb#L27-L33
Regarding files, you'll need to construct a multipart body. Actually, there isn't a good mechanism for this but this might be a good start: https://github.com/socketry/multipart-post/blob/2b1235a25bc3ff03d907785caa83f09c69d6f501/lib/multipart/post/multipartable.rb
Doing it in-memory is okay if you have enough memory/swap to do so.
Beyond that, what we should probably introduce is
Protocol::HTTP::Multipart
which does streaming from disk/memory.multipart-post
has most of the pieces but it was primarily designed forN…