PhoenixKit.UploadsParentFolder (phoenix_kit v2.26.0)

Copy Markdown View Source

Host hook for core's own uploads (user avatars, branding logos, media selector uploads with a scope):

config :phoenix_kit, :uploads_parent_folder, {MyApp.Media, :parent_for}

called as parent_for(kind, actor_uuid, subject) (or parent_for(kind, actor_uuid)), kind ∈ :avatar | :branding, returning {:ok, folder_uuid} or nil (root, default).

  • actor_uuid is whoever is uploading. On the admin user form that is the admin and subject is the user being edited; Auth.update_user_avatar/4 passes the avatar's owner as both.
  • The avatar and branding pickers pass the answer to MediaSelectorModal as scope_folder_id, which also scopes browsing to that folder's subtree — files outside it are not offered in those pickers.
  • The pickers consult the hook when they open, not on page mount, so a hook that lazily creates its folder does so only when someone uploads.
  • An answer that is not a UUID, names no folder, or names a trashed folder is treated as nil, as is a hook that raises or exits.

Summary

Functions

Attach file to the host folder for kind; no-op when the host answers nil.

Types

hook()

@type hook() :: {module(), atom()} | nil

Functions

place(file, kind, actor_uuid, subject \\ nil)

@spec place(PhoenixKit.Modules.Storage.File.t(), atom(), String.t() | nil, term()) ::
  :ok

Attach file to the host folder for kind; no-op when the host answers nil.

resolve(kind, actor_uuid, subject \\ nil)

@spec resolve(atom(), String.t() | nil, term()) :: String.t() | nil