You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defmodule Storage.ProfileFile do
use Waffle.Definition
use Waffle.Ecto.Definition
@versions [:original]
def storage_dir(_version, {_file, profile}) do
"profiles/#{profile.id}"
end
end
Hey,
This option is needed for local type of storage.
By default, waffle stores your files in storage directory related to your project's root path.
Depending on how you want to serve files, you may want to have a different directory structure.
As an example, you may want to store files in "priv/waffle/public/users/:id/avatar.jpg" and have only "users/:id/avatar.jpg" part in url.
In order to achieve this, you can define `storage_dir_prefix` in global config as "priv/waffle/private" to make sure by default your files are private (considering you configured access restrictions when serving files from that directory) and for public files you just define storage_dir_prefix function in each public uploader with a value of "priv/waffle/public" to override the default setting.
That way you can achieve elaborate directory structure and not expose that structure in urls.
Environment
Erlang/OTP 23 [erts-11.1.5] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [hipe]
Elixir 1.12.3 (compiled with Erlang/OTP 22)
waffle 1.1.5
waffle_ecto 0.0.11
Issue
I am not sure if this is an actual bug or I misunderstand the role of
storage_dir
config.Round about I have the following code:
Expected behavior
I would expect the newly uploaded file is saved in
storage/profiles/<SOME_ID>/FILENAME.EXT
Actual behavior
The newly uploaded file is actually saved in
profiles/<SOME_ID>/FILENAME.EXT
The text was updated successfully, but these errors were encountered: