Last active
August 2, 2018 17:13
-
-
Save chathurangat/1ca01377ec936635b289e23fcdf729ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.springbootdev.amazon.s3.example.aws.service.AmazonS3ClientService; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.web.bind.annotation.*; | |
import org.springframework.web.multipart.MultipartFile; | |
import java.util.HashMap; | |
import java.util.Map; | |
@RestController | |
@RequestMapping("/files") | |
public class FileHandlerController { | |
@Autowired | |
private AmazonS3ClientService amazonS3ClientService; | |
@PostMapping | |
public Map<String, String> uploadFile(@RequestPart(value = "file") MultipartFile file) | |
{ | |
this.amazonS3ClientService.uploadFileToS3Bucket(file, true); | |
Map<String, String> response = new HashMap<>(); | |
response.put("message", "file [" + file.getOriginalFilename() + "] uploading request submitted successfully."); | |
return response; | |
} | |
@DeleteMapping | |
public Map<String, String> deleteFile(@RequestParam("file_name") String fileName) | |
{ | |
this.amazonS3ClientService.deleteFileFromS3Bucket(fileName); | |
Map<String, String> response = new HashMap<>(); | |
response.put("message", "file [" + fileName + "] removing request submitted successfully."); | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment