PhxMediaLibrary.Storage.Disk (PhxMediaLibrary v0.6.1)

Copy Markdown View Source

Local filesystem storage adapter.

Configuration

config :phx_media_library,
  disks: [
    local: [
      adapter: PhxMediaLibrary.Storage.Disk,
      root: "priv/static/uploads",
      base_url: "/uploads"
    ]
  ]

Options

  • :root - Root directory for file storage (required)
  • :base_url - Base URL for generating public URLs (required)
  • :download_base_url - Base URL where PhxMediaLibrary.Plug.MediaDownload is mounted. Required when using download: true or signed: true URL generation. Example: "/media".
  • :secret_key_base - HMAC secret for signing local URLs. Required when using signed: true. Should be at least 32 bytes of random data.

Signed and Download URLs

When PhxMediaLibrary.Plug.MediaDownload is mounted in the router and download_base_url + secret_key_base are configured, local URLs can be signed and/or served with a Content-Disposition: attachment header:

# router.ex
forward "/media", PhxMediaLibrary.Plug.MediaDownload, disk: :local

# config.exs
config :phx_media_library,
  disks: [
    local: [
      adapter: PhxMediaLibrary.Storage.Disk,
      root: "priv/static/uploads",
      base_url: "/uploads",
      download_base_url: "/media",
      secret_key_base: "long-random-secret-at-least-32-bytes"
    ]
  ]

Then generate URLs via PhxMediaLibrary.download_url/3 or PhxMediaLibrary.signed_url/3.