Handle Image Upload by Transaction like approach?

My Application needs users to upload their profile picture,Lets say, On image upload i have to store image in s3 bucket and image name in database. If either one of these operation fails, the entire image upload operation should also fail, what is the best approach/lib to achieve this?

I am in the same situation such as I have transactions that touch the db, rabbitmq and s3. I do it with Ecto.Multi, putting the non-db parts in run-calls and sort it such, that the s3/rabbitmq calls are at the end. That works nicely as long as you have only one non-db part in your transaction and it is possible to execute it at the end.

Indeed, and if you can write 'undo’s for the actions as well then you could easily aggregate them all and if any fail then run the undo’s to roll them back (though that could fail too, say like a network issue or so).