Created
March 24, 2021 15:46
-
-
Save mmafrar/c4dcf6630196a7df3822672e3655cb41 to your computer and use it in GitHub Desktop.
Working with Amazon S3 presigned URLs in Spring Boot
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
package com.example.demo; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.http.HttpStatus; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.web.bind.annotation.CrossOrigin; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.PostMapping; | |
import org.springframework.web.bind.annotation.RequestBody; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestParam; | |
import org.springframework.web.bind.annotation.RestController; | |
import javax.servlet.http.HttpServletRequest; | |
import java.util.Map; | |
@RestController | |
@RequestMapping("/api/v1/files") | |
@CrossOrigin(origins = "*", maxAge = 3600) | |
public class FileControllerNew { | |
private static final String FILE_NAME = "fileName"; | |
@Autowired | |
FileServiceNew fileServiceNew; | |
@GetMapping | |
public ResponseEntity<Object> findByName(HttpServletRequest request, @RequestBody(required = false) Map<String, String> params) { | |
final String path = request.getServletPath(); | |
if (params.containsKey(FILE_NAME)) | |
return new ResponseEntity<>(fileServiceNew.findByName(params.get(FILE_NAME)), HttpStatus.OK); | |
} | |
@PostMapping | |
public ResponseEntity<Object> saveFile(@RequestParam("extension") String extension) { | |
return new ResponseEntity<>(fileServiceNew.save(extension), HttpStatus.OK); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment