Wraith. Uploads behaviour
(Wraith v0.1.0)
View Source
Images (and other files) authors upload: feature images, inline post
images, avatars. One adapter per environment
(config :wraith, Wraith.Uploads, adapter: …):
Wraith.Uploads.Local— files underpriv/uploads(dev, tests, a single container with a volume), served at/uploads/<key>Wraith.Uploads.S3— a bucket through ex_aws; the URL is the bucket's public URL or a CDN in front of it (:public_url)
Keys are <yyyy>/<mm>/<uuid>.<ext>; store/3 takes the bytes (or a
path), checks the type and size (10 MB), and returns {:ok, url}.
Summary
Functions
The image library: uploaded originals (never the resized variants), newest
first. limit: (default 60).
Store content (binary) under a fresh key for content_type. opts[:name]
keeps a readable stem.
Store a file on disk (a LiveView upload entry's path).
Like store/3 but also returns the image's dimensions (nil for non-raster
types), so a feature image's width/height can be saved with the post.
Store a file on disk and return its dimensions too.
Is this key a generated variant (not an original)?
Callbacks
@callback list(keyword()) :: [ %{ key: String.t(), url: String.t(), size: non_neg_integer(), modified: String.t() | nil } ]
Functions
The image library: uploaded originals (never the resized variants), newest
first. limit: (default 60).
Store content (binary) under a fresh key for content_type. opts[:name]
keeps a readable stem.
The declared type is only trusted after the bytes agree with it: a browser,
an agent or a remote server can say image/png about anything, and an SVG
(or an HTML file dressed as one) served from our origin would run script
with our cookies. sniff/2 checks magic bytes for every raster type and
the root element for SVG; PDF must start with %PDF-.
Store a file on disk (a LiveView upload entry's path).
@spec store_image(binary(), String.t(), keyword()) :: {:ok, String.t(), map() | nil} | {:error, String.t()}
Like store/3 but also returns the image's dimensions (nil for non-raster
types), so a feature image's width/height can be saved with the post.
Store a file on disk and return its dimensions too.
Is this key a generated variant (not an original)?