PhxMediaLibrary.MediaAdder (PhxMediaLibrary v0.6.1)

Copy Markdown View Source

Builder struct for adding media to a model.

This module provides a fluent API for configuring media before it is persisted to storage and the database.

You typically won't use this module directly - instead use the functions in PhxMediaLibrary which delegate here.

Summary

Functions

Create a new MediaAdder for the given model and source.

Finalize and persist the media.

Set a custom filename.

Enable responsive image generation.

Disable automatic metadata extraction for this media.

Types

source()

@type source() ::
  Path.t() | {:url, String.t()} | {:url, String.t(), keyword()} | map()

t()

@type t() :: %PhxMediaLibrary.MediaAdder{
  custom_filename: String.t() | nil,
  custom_properties: map(),
  disk: atom() | nil,
  extract_metadata: boolean(),
  generate_responsive: boolean(),
  model: Ecto.Schema.t(),
  source: source()
}

Functions

new(model, source)

@spec new(Ecto.Schema.t(), source()) :: t()

Create a new MediaAdder for the given model and source.

to_collection(adder, collection_name, opts \\ [])

@spec to_collection(t(), atom(), keyword()) ::
  {:ok, PhxMediaLibrary.Media.t()} | {:error, term()}

Finalize and persist the media.

using_filename(adder, filename)

@spec using_filename(t(), String.t()) :: t()

Set a custom filename.

with_custom_properties(adder, properties)

@spec with_custom_properties(t(), map()) :: t()

Set custom properties.

with_responsive_images(adder)

@spec with_responsive_images(t()) :: t()

Enable responsive image generation.

without_metadata(adder)

@spec without_metadata(t()) :: t()

Disable automatic metadata extraction for this media.

By default, PhxMediaLibrary extracts metadata (dimensions, EXIF, etc.) from uploaded files. Use this to skip extraction for a specific upload.

Examples

post
|> PhxMediaLibrary.add(upload)
|> PhxMediaLibrary.without_metadata()
|> PhxMediaLibrary.to_collection(:images)