-
Notifications
You must be signed in to change notification settings - Fork 149
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
One does not simply delete an Arc attachment #40
Comments
@jerodsanto I fugured out a way to delete the image going by the documentation for delete in the Arc README Assuming you have already stored and uploaded an avatar to this user deleting it will look something like this.
The problem is that it only deletes the the image from wherever your storing it at, ex: S3, but doesn't remove the path url that is associated to the model. If I figure out how to get the correct behavior I'll post an update here. |
There is no convenience yet for deleting objects through Ecto / arc_ecto. I will consider adding this. However, to delete for now, the best option is likely to:
user = Repo.get!(User, 1) # Assume there is a property :avatar on User
user
|> User.changeset(%{avatar: nil})
|> Repo.update!()
:ok = Avatar.delete({user.avatar, user})
# Since the above deletion doesn't really need to happen synchronously, you can delete it asynchronously to speed up the request/response.
# spawn(fn -> Avatar.delete({user.avatar, user}) end) |
Thank you @stavro. |
This is pretty straight forward. I think updating the readme will be sufficient. I'll do that tomorrow and submit a PR. Thanks again. |
When calling It's raising this error: Any thoughts on what to do next? |
Ah - if you currently send Ok - for now send it through Ecto.Changeset.change(user, %{avatar: nil}) rather than sending through cast_attachments. I'll get this fixed shortly. |
When I try to delete attachment from
It returns |
@mamantoha I was running into the same issue, but got things working with: attachment = Repo.get Attachment, 1
path = Rumbl.Image.url({attachment.file, attachment})
[path | _] = String.split path, "?" # strips the "?v=1234" from the URL string
Rumbl.Image.delete({path, attachment}) Or perhaps more idiomatically: attachment = Repo.get Attachment, 1
path =
Rumbl.Image.url({attachment.file, attachment})
|> String.split("?")
|> List.first
Rumbl.Image.delete({path, attachment}) Apparently the return from "/foo/bar?v=1234"
"/foo/bar" Hope this helps! |
Deleting seems to remove file(s), but not directory it was in. |
Are there any plans to add an easier / more automatic way of removing files? Ideally I would like to just set the property for my attachment to |
Let's say I want to delete an image attachment, but not replace it with a new one. I can't seem to figure out how to get that done.
I tried replacing the file field with a hidden field of same name and
nil
value or""
value:But that gives me:
When calling
cast_attachments
. I know there is anArc.Actions.Delete
, but I don't know how to invoke it.If you lend me a hand I'd be happy to update the README to include this procedure.
Thanks in advance. 🍻
The text was updated successfully, but these errors were encountered: