Open victorolinasc opened 4 years ago
Has the feature been added?
AFAICT streaming is not directly supported. However, I was able to get a stream in the response body with this code:
# returns {:ok, %Tesla.Env.t()}
# env.body contains a stream resource
def get_object_stream(token, bucket_name, object) do
{:ok, env} =
Tesla.client(
[
{Tesla.Middleware.Headers, [{"authorization", "Bearer #{token}"}]}
],
{Tesla.Adapter.Mint, [body_as: :stream]}
)
|> GoogleApi.Storage.V1.Api.Objects.storage_objects_get(bucket_name, object, alt: "media")
end
The two key bits of this code snippet:
Tesla
client using an adapter with streaming capabilities and set the body_as: :stream
option. Mint
is one adapter that does streaming. There are other supported libraries for streaming in Tesla
.alt: "media"
option to storage_objects_get
. Without a streaming adapter you will get the entire file in the response body. With a streaming adapter, you get a stream.
It would be nice if we could stream file contents in a nice to have Elixir API like
File.Stream
like:https://www.poeticoding.com/elixir-streams-to-process-large-http-responses-on-the-fly/
Is that supported by the HTTP API?