Class FileServiceImpl

java.lang.Object
com.example.blogs.app.api.file.service.FileServiceImpl
All Implemented Interfaces:
FileService

@Service public class FileServiceImpl extends Object implements FileService
Orchestrates file upload operations by coordinating storage upload and metadata persistence.
  • Constructor Details

    • FileServiceImpl

      public FileServiceImpl()
  • Method Details

    • upload

      public FileEntity upload(MultipartFile file, String filePath)
      Uploads a file to S3 storage and saves its metadata to the repository. Generates a unique identifier, normalizes the path, detects content type, and uploads to S3.
      Specified by:
      upload in interface FileService
      Parameters:
      file - the multipart file to upload
      filePath - the storage path where the file should be uploaded
      Returns:
      the saved file entity with metadata
      Throws:
      FailedToUploadFileException - if the S3 upload fails
    • delete

      public void delete(FileEntity fileEntity)
      Deletes a file from S3 storage and removes its metadata from the repository. Removes the file from S3 bucket first, then deletes the metadata record.
      Specified by:
      delete in interface FileService
      Parameters:
      fileEntity - the file entity to delete