elixir - How to duplicate an arc_ecto upload -


one of models of phoenix app has logo, uses arc_ecto , uploads s3.

i'm duplicating 1 of records , want have same image logo.

in changeset have:

|> cast_attachments(params, [:logo]) 

the value of logo original item is:

iex(21)> myrepo.get(mymodel, 1).logo %{file_name: "mylogo.png", updated_at: #ecto.datetime<2017-09-12 12:31:58>} 

but if try set directly, error (arc.file.new doesn't accept structure, makes sense).

i tried extracting s3 url of original logo. didn't return error, didn't add logo:

iex(22)> myrepo.get(mymodel, 2).logo nil 

what's right way manage scenario? hints?

i managed fix issue, there 2 things missing:

1 - needed add allow_paths: true cast_attachments

|> cast_attachments(params, [:logo], allow_paths: true) 

2 - had on uploader:

def storage_dir(_version, {_file, my_model})   "/my_models/#{my_model.id}/logo/" end 

so using id set storage route. duplicating element, still didn't have id , therefore route incorrect. split insert of duplicated element , update of logo 2 steps.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -