Class TransactionalFileUploader

java.lang.Object
com.example.blogs.app.api.post.service.TransactionalFileUploader

@Service public class TransactionalFileUploader extends Object
Handles file uploads with automatic rollback when database transactions fail.
  • Constructor Details

    • TransactionalFileUploader

      public TransactionalFileUploader()
  • Method Details

    • uploadWithTransactionRollback

      public FileEntity uploadWithTransactionRollback(MultipartFile file, String path)
      Uploads a file and registers a transaction synchronization callback to delete it if the transaction rolls back. Ensures uploaded files are cleaned up from S3 when the associated database transaction fails.
      Parameters:
      file - the multipart file to upload
      path - the storage path where the file should be uploaded
      Returns:
      the uploaded file entity with metadata
      Throws:
      FailedToRollbackS3FileException - if the rollback cleanup fails