FalEx.Storage (fal_ex v0.1.0)

View Source

Storage client for handling file uploads and transformations.

Automatically uploads files to fal.ai storage and transforms input payloads to replace file references with URLs.

Summary

Functions

Creates a new storage client.

Transforms input data by uploading any file references.

Uploads a file to fal.ai storage.

Types

t()

@type t() :: %FalEx.Storage{config: FalEx.Config.t()}

Functions

create(config)

Creates a new storage client.

transform_input(storage, input)

@spec transform_input(t(), any()) :: any()

Transforms input data by uploading any file references.

Recursively processes the input, uploading any binary data or file paths and replacing them with URLs.

Examples

input = %{
  prompt: "A cat",
  image: File.read!("cat.jpg")
}

transformed = Storage.transform_input(storage, input)
# => %{prompt: "A cat", image: "https://fal.media/..."}

upload(storage, data_or_path, opts \\ [])

@spec upload(t(), binary() | Path.t(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Uploads a file to fal.ai storage.

Parameters

  • data - Binary file data or a file path
  • opts - Upload options

Options

  • :file_name - Name of the file
  • :content_type - MIME type of the file

Examples

{:ok, url} = Storage.upload(storage, File.read!("image.png"),
  file_name: "image.png",
  content_type: "image/png"
)