How to delete an image on s3 using ex_aws & arc in Phoenix

Hi, I’m using ex_aws and arc to upload images to AWS S3.

Everything is working fine, but I can’t get the object delete function to work. The example on the arc page is as follows:

Without a scope:

{:ok, path} = DummyDefinition.store("/Images/me.png")
:ok = DummyDefinition.delete(path)

With a scope:

user = Repo.get! User, 1
{:ok, path} = DummyDefinition.store({"/Images/me.png", user})
:ok = DummyDefinition.delete({path, user})

I’m new to Elixir and Phoenix (latest versions of both). I’m not sure what to replace DummyDefinition with in my delete function.

i’d appreciate any pointers in the right direction. Thanks.

Hi, I’m using ex_aws and arc to upload images to AWS S3.

Everything is working fine, but I can’t get the object delete function to work. The example on the arc page is as follows:

I don’t know anything about arc (other than it appears to be all
macros and no documentation!) but – why don’t you just use
ExAws.S3 directly? It’s pretty straightforward, e.g.

ExAws.S3.delete_object(“bucket-name”, “file-name”) |> ExAws.request()

You have a good point there Sir. Less magic is good.

Bear in mind ex_aws_s3 is also undocumented. Is this the norm in Elixir world or anomalous?

Replace DummyDefinition with your uploader module. Then delete/1 will trigger Arc.Actions.Delete.delete/2.

Arc is good when it comes to image attachments, it gives you ability to validate, transform images, create thumbnails easily. with arc_ecto you can define a field as Definition.Type + cast_attachment and let it do the job, much similar to CarrierWave in rails.

So, suppose your file name is my_image.png, and you have 2 versions of the image: [:original, :thumb]. you only have to ask arc to delete it once, both image versions will be deleted.