arc icon indicating copy to clipboard operation
arc copied to clipboard

How can I configure for testing?

Open mrkaspa opened this issue 9 years ago • 6 comments

I want to configure in a phoenix app for production to use aws bucket but for dev & test store the files locally?

mrkaspa avatar Dec 31 '15 16:12 mrkaspa

Hey, I ran into this same issue.

It looks like the definition defaults to Arc.Storage.S3 unless you explicitly set it to Arc.Storage.Local in the __storage method in your own implementation (e.g. Application.Avatar).

I ended up changing config/test.exs to:

config :arc,
  definition: Arc.Storage.Local

And then altered my implementation (web/uploaders/avatar.exs) to:

  def __storage do
    definition = Application.get_env(:arc, :definition)

    case definition do
      :nil -> Arc.Storage.S3
      _    -> definition
    end
  end

Hope this helps!

baoist avatar Jan 05 '16 08:01 baoist

@baoist that's a good approach it'll be good this be the default in the library

mrkaspa avatar Jan 05 '16 13:01 mrkaspa

Yes, it would be nice to have this supported by the library. I'm currently adding this code across 4 different definitions. That said, it works beautifully. Thanks @baoist.

The only change I made was to use a storage key instead of calling it definition.

config :arc, storage: Arc.Storage.Local

nathany avatar Apr 20 '16 17:04 nathany

This is a bit cleaner as well:

def __storage do
  Application.get_env(:arc, :storage) || Arc.Storage.S3
end

Since I'm an Elixir newb, I did some tests in IEX to ensure that :nil || "something" works just like nil || "something" and Application.get_env(:arc, :storage) returns nil anyway.

nathany avatar Apr 20 '16 20:04 nathany

@nathany Application.get_env/3 uses the third argument as the default value, so the null-coalescing operator isn't necessary here.

Application.get_env(:arc, :storage, Arc.Storage.S3)

nkezhaya avatar Nov 12 '16 17:11 nkezhaya

You can specify storage config since version 0.6.0: https://github.com/stavro/arc/commit/848c17e5d51e658e10e6824cb4e97bab9e871456

@stavro you can close it!

nashby avatar May 23 '17 18:05 nashby