SlowpokeWaffle v0.3.0 SlowpokeWaffle View Source

Provides a storage module for Waffle.

With this storage method, all images are stored locally first, then are queued to be uploaded to AWS, and after uploading is done, the local copy is deleted. Either an uploading is in progress or is already done, the returned url for the resource is always valid.

Examples

To use it, define your configured module:

defmodule MyApp.Storage do
  use SlowpokeWaffle
end

and then you can add it to config:

config :waffle, storage: MyApp.Storage

By default it uses Waffle.Storage.Local for locally saved files and Waffle.Storage.S3 for uploadings, but you can change this behavior by providing options when using. The example above is equivalent to the following one:

defmodule MyApp.Storage do
  use SlowpokeWaffle,
    local_storage: Waffle.Storage.Local,
    inet_storage: Waffle.Storage.S3
end

Configuration

Configuration of storages is pretty much the same as with default waffle storages:

config :waffle,
  storage: MyApp.Storage,
  storage_dir: "/pictures_with_cats",
  bucket: "<your-bucket-name>",
  virtual_host: true

config :ex_aws,
  access_key_id: ["<your-key-id>", :instance_role],
  secret_access_key: ["<your-secret-key>", :instance_role],
  region: "<your-region>"

Static

You may want to replace your Plug.Static with the one that provides your storage:

plug MyApp.Storage.StaticPlug,
  at: "/uploads",
  from: {:my_app, "uploads"}

See SlowpokeWaffle.StaticPlug for more details.