Skip to content

Instantly share code, notes, and snippets.

@chathurangat
Last active August 2, 2018 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurangat/1ca01377ec936635b289e23fcdf729ed to your computer and use it in GitHub Desktop.
Save chathurangat/1ca01377ec936635b289e23fcdf729ed to your computer and use it in GitHub Desktop.
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