Skip to content

How to consume a Tesla.Adapter.Finch stream body response #786

Closed

Description

@pau-riosa

Is there any documentation how to consume a stream body coming from Tesla.Adapter.Finch?

I'd like to consume a stream data and create a wav file from it.

Activity

  1. yordis commented on Jul 11, 2025

    @yordis
    Member

    Could you do something like,

    defmodule AudioStreamer do
      def client do
        Tesla.client([
          {Tesla.Middleware.BaseUrl, "https://audio-service.com"}
        ], {Tesla.Adapter.Finch, name: MyFinch})
      end
      
      def stream_to_wav_file(audio_url, output_path) do
        case Tesla.get(client(), audio_url, opts: [adapter: [response: :stream]]) do
          {:ok, %Tesla.Env{body: stream}} ->
            File.open!(output_path, [:write, :binary])
            |> write_stream_to_file(stream)
            |> File.close()
            
            {:ok, output_path}
          
          {:error, reason} ->
            {:error, reason}
        end
      end
    end
  2. locked and limited conversation to collaborators on Jul 11, 2025
  3. converted this issue into a discussion #787 on Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions