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

2 pictures in one schema #100

Open
HendrikPetertje opened this issue Oct 30, 2018 · 1 comment
Open

2 pictures in one schema #100

HendrikPetertje opened this issue Oct 30, 2018 · 1 comment

Comments

@HendrikPetertje
Copy link

HendrikPetertje commented Oct 30, 2018

Hey there, I've been using Arc and Arc Ecto with lot's of luck so far. I'm however dealing with a small minor issue.

Say i have this model:

User:

field type
name string
email string
uuid string
avatar string (BaseImage.Type)
status_image string (BaseImage.Type)

I want a thumb and a 500x500px picture for both the avatar and the status-image, so I'm not bothering writing 2 uploaders with identical code.

Then I cast attachments like this in the changeset:

cast_attachments(changeset, attrs, [:avatar, :status_image])

I don't really want users to be able to decide the filename, so I would rename the folder and file after upload to something like this.

  def filename(version, _) do
    "picture.jpg"
  end

  def storage_dir(_, {_, %{ uuid: uuid } }) do
    "uploads/section/pictures/#{uuid}"/[avatar||status_image]
  end

*Problem however is that i have no way of knowing if i'm dealing with :avatar or :status_image when processing a file, the only context I seem to get is the complete changeset. So the second upload will simply just override the first one on the disk if a user uploads both an avatar and a status-image. *
Is there a way to make the Uploader aware of which "field" it's dealing with?
(Sure I could create a new model that keeps tabs on images, but it seems a bit of a weird hoop).

@achempion
Copy link

@HendrikPetertje Hi, how did you fix the issue?

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