Storage.Attachment (PhoenixContribStorage v0.1.0)

View Source

Provides macros for adding file attachments to Ecto schemas.

This module allows you to easily add file attachment functionality to your Ecto schemas, similar to Rails ActiveStorage.

Usage

defmodule MyApp.User do
  use Ecto.Schema
  use Storage.Attachment

  schema "users" do
    field :name, :string
    has_one_attached :avatar
    has_many_attached :documents
  end
end

This will add virtual fields and helper functions for managing attachments.

Summary

Functions

Attaches multiple blobs to a record.

Attaches a single blob to a record.

Checks if a record has any attachments for the given name.

Detaches all attachments for a given name without deleting the blobs.

Detaches a single attachment without deleting the blob.

Gets all attachments for a record.

Gets a single attachment for a record.

Defines a has_many_attached relationship.

Defines a has_one_attached relationship.

Purges all attachments and their blobs for a given name.

Functions

attach_many(record, name, blobs)

Attaches multiple blobs to a record.

attach_one(record, name, blob)

Attaches a single blob to a record.

attached?(record, name)

Checks if a record has any attachments for the given name.

detach_many(record, name)

Detaches all attachments for a given name without deleting the blobs.

detach_one(record, name)

Detaches a single attachment without deleting the blob.

get_many(record, name)

Gets all attachments for a record.

get_one(record, name)

Gets a single attachment for a record.

has_many_attached(name)

(macro)

Defines a has_many_attached relationship.

has_one_attached(name)

(macro)

Defines a has_one_attached relationship.

purge_attached(record, name)

Purges all attachments and their blobs for a given name.