# `Waffle.Actions.Store`
[🔗](https://github.com/elixir-waffle/waffle/blob/v2.0.0/lib/waffle/actions/store.ex#L1)

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` or `https` file

  * A 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 map with a filename and stream keys (eg, `%{filename: "image.png", stream: %Stream{...}}`)

  * 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})

See [Fetching remote files](`m:Waffle.Definition.Storage#module-fetching-remote-files`)
for setup and configuration.

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}`).

# `store`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
