Support streaming requests (Transfer-Encoding: chunked) #1508
Replies: 4 comments
-
Meta: Hi, in order to turn this from an Issue into a Help Discussion, I pushed a button and made it so. |
Beta Was this translation helpful? Give feedback.
-
I think I've managed to sort this out and it really has nothing to do with Faraday. In essence, the solution here (I think) is multiple PUT requests with the appropriate headers for chunk_size = 2*1024*1024
io = File.new(file_path, "r")
io.each_with_index(nil, chunk_size) do |chunk, index|
# set the headers here & send a PUT request
end In any case, it might perhaps be interesting to implement some sort of a module that would/could magically do this. |
Beta Was this translation helpful? Give feedback.
-
Hi @dshorthouse, thank you for raising this! I don't have enough experience with streaming requests to know how much work would be needed, especially on the adapters' side, but I'd be happy to review a design proposal if anyone would be interested to work on it 🙂 |
Beta Was this translation helpful? Give feedback.
-
You're better off probably just using an http client which supports what you want. For example, httpx supports streaming requests, either by using the |
Beta Was this translation helpful? Give feedback.
-
Apologies in advance for the inquiry, but am not sure where else (or how else) to pose my inquiry. I make use of a
OAuth2::Client
withFaraday.default_adapter
and am trying to figure out how to do a PUT with a chunked transfer encoding to stream a file to an endpoint. I can useFile.read
to put a file in memory and then PUT it in the body of a request, but this defeats the purpose. Is it possible to use Faraday in conjunction withOAuth2::Client
to do such a thing? Is there perhaps some Faraday middleware module comparable toFaraday::Multipart::FilePart
that would/could construct a chunked body for a large file to PUT? Thanks for any pointers.Beta Was this translation helpful? Give feedback.
All reactions