Waffle.Actions.Store (waffle v1.1.6)
Store files to a defined adapter.
The definition module responds to Avatar.store/1
which
accepts either:
A path to a local file
A path to a remote
http
orhttps
fileA map with a filename and path keys (eg, a
%Plug.Upload{}
)A map with a filename and binary keys (eg,
%{filename: "image.png", binary: <<255,255,255,...>>}
)A two-element tuple consisting of one of the above file formats as well as a scope map
Example usage as general file store:
# Store any locally accessible file
Avatar.store("/path/to/my/file.png") #=> {:ok, "file.png"}
# Store any remotely accessible file
Avatar.store("http://example.com/file.png") #=> {:ok, "file.png"}
# Store a file directly from a `%Plug.Upload{}`
Avatar.store(%Plug.Upload{filename: "file.png", path: "/a/b/c"}) #=> {:ok, "file.png"}
# Store a file from a connection body
{:ok, data, _conn} = Plug.Conn.read_body(conn)
Avatar.store(%{filename: "file.png", binary: data})
Example usage as a file attached to a scope
:
scope = Repo.get(User, 1)
Avatar.store({%Plug.Upload{}, scope}) #=> {:ok, "file.png"}
This scope will be available throughout the definition module to be
used as an input to the storage parameters (eg, store files in
/uploads/#{scope.id}
).
Link to this section Summary
Link to this section Functions
Link to this function