0
votes

I'm trying to find a way to store images and 3d assets as I think they shouldn't be stored in the database (Azure Database for MySQL).

I'm thinking that it's better to store them in a cloud storage, so I chose Azure Blob Storage for this reason.

I think that I should store the file name, and other properties onto the database, and using the fileID returned from the database to obtain the location of the item from Azure Blob Storage.

But I am a worried about transactional safety, what should I do in the event of failure? E.g. if uploading to Azure Blob Storage fails, should I delete the record in attempts to 'undo'?

Is there a better way to do this? Is it recommended at all?

Edit: On second thought, a better idea might be to first upload to Azure Blob Storage, and then only after a successful upload, to upload a record onto the database. I think it is safer this way.

1

1 Answers

0
votes
  • In a try-catch block, check if an image's URL exist first, if not, upload an image to storage and get the file URL
  • if upload success, start a transaction and add the new record to the database with the image URL.
  • if the transaction failed, delete the image