Class StorageController

java.lang.Object
callofproject.dev.project.controller.StorageController

@RestController @RequestMapping("api/project/storage") public class StorageController extends Object
This class represents a controller for managing storage-related operations. It handles HTTP requests related to storage and interacts with the S3Service.
  • Constructor Summary

    Constructors
    Constructor
    Description
    StorageController(S3Service storageService)
    Constructs a new StorageController with the provided dependencies.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<String>
    deleteFile(String fileName)
    Handles the HTTP DELETE request to delete a file from the storage service.
    org.springframework.http.ResponseEntity<org.springframework.core.io.ByteArrayResource>
    downloadFile(String fileName)
    Handles the HTTP GET request to download a file from the storage service.
    org.springframework.http.ResponseEntity<String>
    Handles the HTTP GET request to find an image by its name from the storage service.
    org.springframework.http.ResponseEntity<String>
    uploadFile(File file, String fileName)
    Handles the HTTP POST request to upload a file to the storage service using a File object.
    org.springframework.http.ResponseEntity<String>
    uploadFile(org.springframework.web.multipart.MultipartFile file, String fileName)
    Handles the HTTP POST request to upload a file to the storage service using a File object.
    org.springframework.http.ResponseEntity<String>
    uploadFileAndGetUrl(org.springframework.web.multipart.MultipartFile file, String fileName)
    Handles the HTTP POST request to upload a file to the storage service using MultipartFile and obtain its URL.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StorageController

      public StorageController(S3Service storageService)
      Constructs a new StorageController with the provided dependencies.
      Parameters:
      storageService - The S3Service instance used for handling storage-related operations.
  • Method Details

    • uploadFile

      @PostMapping("/upload/multipart") public org.springframework.http.ResponseEntity<String> uploadFile(@RequestParam("file") org.springframework.web.multipart.MultipartFile file, @RequestParam("name") String fileName)
      Handles the HTTP POST request to upload a file to the storage service using a File object.
      Parameters:
      file - The File object representing the file to be uploaded.
      fileName - The name to be assigned to the uploaded file.
      Returns:
      ResponseEntity with a message indicating the success of the upload, or an error message in case of failure.
    • uploadFileAndGetUrl

      @PostMapping("/upload/multipart/url") public org.springframework.http.ResponseEntity<String> uploadFileAndGetUrl(@RequestParam("file") org.springframework.web.multipart.MultipartFile file, @RequestParam("name") String fileName)
      Handles the HTTP POST request to upload a file to the storage service using MultipartFile and obtain its URL.
      Parameters:
      file - The MultipartFile containing the file to be uploaded.
      fileName - The name to be assigned to the uploaded file.
      Returns:
      ResponseEntity with the URL of the uploaded file, or an error message in case of failure.
    • uploadFile

      @PostMapping("/upload/file") public org.springframework.http.ResponseEntity<String> uploadFile(@RequestParam("file") File file, @RequestParam("name") String fileName)
      Handles the HTTP POST request to upload a file to the storage service using a File object.
      Parameters:
      file - The File object representing the file to be uploaded.
      fileName - The name to be assigned to the uploaded file.
      Returns:
      ResponseEntity with a message indicating the success of the upload, or an error message in case of failure.
    • downloadFile

      @GetMapping("/download/{fileName}") public org.springframework.http.ResponseEntity<org.springframework.core.io.ByteArrayResource> downloadFile(@PathVariable String fileName)
      Handles the HTTP GET request to download a file from the storage service.
      Parameters:
      fileName - The name of the file to be downloaded.
      Returns:
      ResponseEntity with the file data as a ByteArrayResource, or an error message in case of failure.
    • deleteFile

      @DeleteMapping("/delete/{fileName}") public org.springframework.http.ResponseEntity<String> deleteFile(@PathVariable String fileName)
      Handles the HTTP DELETE request to delete a file from the storage service.
      Parameters:
      fileName - The name of the file to be deleted.
      Returns:
      ResponseEntity with a message indicating the success of the deletion, or an error message in case of failure.
    • findImage

      @GetMapping("find/image") public org.springframework.http.ResponseEntity<String> findImage(@RequestParam("name") String name)
      Handles the HTTP GET request to find an image by its name from the storage service.
      Parameters:
      name - The name of the image to be retrieved.
      Returns:
      ResponseEntity with the image data as a String, or an error message in case of failure.