arc
arc copied to clipboard
How can I configure for testing?
I want to configure in a phoenix app for production to use aws bucket but for dev & test store the files locally?
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 that's a good approach it'll be good this be the default in the library
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
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 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)
You can specify storage
config since version 0.6.0: https://github.com/stavro/arc/commit/848c17e5d51e658e10e6824cb4e97bab9e871456
@stavro you can close it!