Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using arc as standalone storage without saving filename #261

Open
pradosh987 opened this issue Aug 1, 2018 · 1 comment
Open

Using arc as standalone storage without saving filename #261

pradosh987 opened this issue Aug 1, 2018 · 1 comment

Comments

@pradosh987
Copy link

pradosh987 commented Aug 1, 2018

I was looking into using arc with phoenix to handle some images. Even though documentation is good enough, I am still confused about filename used in while storing a file and calling url method. General approach is to create a string field in database column and save file name into it. Even ecto_arc is built around same concept. So my question is, suppose I override filename method and make it dependent only model.uuid(actual uuid but not primary key) then why is it necessary to store filename in database in first place, or why is it required to pass filename while calling store or url methods. In my case filename serve no useful purpose. Shouldn't I able to do so by passing model as scope only?

Consider an example

schema "user" do
    field :name, :string
    field :email, :string
    field :has_avatar, :boolean
    field :has_cover, :boolean

    timestamps()
end

defmodule Firefly.Files.Avatar do
  use Arc.Definition
  @versions [:original]

  def filename(version, {_, scope}) do
    "avatar_#{scope.uuid}"
  end

  def storage_dir(version, {file, scope}) do
    "uploads/images/#{scope.uuid}/"
  end
end

defmodule Firefly.Files.Cover do
  use Arc.Definition
  @versions [:original]

  def filename(version, {_, scope}) do
    "cover_#{scope.uuid}"
  end

  def storage_dir(version, {file, scope}) do
    "uploads/images/#{scope.uuid}/"
  end
end

Two boolean fields can tell if user has uploaded avatar and cover image.

Note: I am coming from Ruby on Rails and relatively new to Elixir eco system, so please forgive if I make some mistake or wrong assumption

@plasticine
Copy link

plasticine commented Oct 7, 2018

Yeah, I’m kinda in the same boat — this design seems really weird to me. I’m not sure what I’m missing. I literally just wrote this code;

MyappStorage.Avatar.url({"", user},:thumb)

Which seems kinda pointless...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants