99import com .groom .sumbisori .domain .file .service .ImageAnalyzeService ;
1010import com .groom .sumbisori .domain .file .service .S3PreSignedUrlService ;
1111import com .groom .sumbisori .domain .file .service .S3UploadService ;
12- import jakarta .servlet .http .HttpServletRequest ;
1312import jakarta .validation .Valid ;
14- import java .io .InputStream ;
1513import java .util .List ;
1614import lombok .RequiredArgsConstructor ;
1715import lombok .extern .slf4j .Slf4j ;
2220import org .springframework .web .bind .annotation .PathVariable ;
2321import org .springframework .web .bind .annotation .PostMapping ;
2422import org .springframework .web .bind .annotation .RequestBody ;
25- import org .springframework .web .bind .annotation .RequestHeader ;
2623import org .springframework .web .bind .annotation .RequestMapping ;
2724import org .springframework .web .bind .annotation .RequestParam ;
28- import org .springframework .web .bind .annotation .RequestPart ;
2925import org .springframework .web .bind .annotation .RestController ;
30- import org .springframework .web .multipart .MultipartFile ;
3126
3227@ RestController
3328@ RequestMapping ("/files" )
@@ -37,7 +32,6 @@ public class FileController implements FileApi {
3732 private final S3PreSignedUrlService s3PreSignedUrlService ;
3833 private final ImageAnalyzeService imageAnalyzeService ;
3934 private final FileLookupService fileLookupService ;
40- private final S3UploadService s3UploadService ;
4135
4236 @ GetMapping ("/{imageIdentifier}" )
4337 public ResponseEntity <byte []> getFileImage (@ LoginUser Long userId , @ PathVariable String imageIdentifier ) {
@@ -56,51 +50,8 @@ public ResponseEntity<List<PreSignedUrlResponse>> createPreSignedUrl(
5650 return ResponseEntity .ok ().body (s3PreSignedUrlService .create (request ));
5751 }
5852
59- @ PostMapping ("/test/presigned-url" )
60- public String createPreSignedUrl (@ RequestBody TestPreSignedUrlRequest request ) {
61- return s3PreSignedUrlService .generatePresignedUploadUrl (
62- request .fileName (),
63- request .contentType (),
64- request .fileSize ()
65- );
66- }
67-
6853 @ GetMapping ("/analyze" )
6954 public ResponseEntity <List <SeafoodRecognitionResponse >> imageAnalyze (@ RequestParam String imageIdentifier ) {
7055 return ResponseEntity .ok (imageAnalyzeService .analyze (imageIdentifier ));
7156 }
72-
73- @ PostMapping ("/multipart-file" )
74- public String uploadMultipartFile (@ RequestPart ("file" ) MultipartFile file ) {
75- try (InputStream inputStream = file .getInputStream ()) {
76- String fileName = file .getOriginalFilename ();
77- long contentLength = file .getSize ();
78- s3UploadService .uploadFileToS3 (inputStream , fileName , contentLength );
79- return "업로드 성공" ;
80- } catch (Exception e ) {
81- log .error (e .getMessage (), e );
82- return "업로드 실패: " + e .getMessage ();
83- }
84- }
85-
86- @ PostMapping ("/stream" )
87- public String uploadStream (
88- HttpServletRequest request ,
89- @ RequestHeader ("file-name" ) String fileName ,
90- @ RequestHeader (value = "Content-Length" , required = false ) Long contentLength
91- ) {
92- try (InputStream inputStream = request .getInputStream ()) {
93- log .info ("요청 Content-Type: {}" , request .getContentType ());
94- long length = (contentLength != null && contentLength > 0 )
95- ? contentLength
96- : inputStream .available ();
97- return "업로드 성공" ;
98- } catch (Exception e ) {
99- log .error ("업로드 실패" , e );
100- return "업로드 실패: " + e .getMessage ();
101- }
102- }
103-
104- record TestPreSignedUrlRequest (String fileName , String contentType , Long fileSize ) {
105- }
10657}
0 commit comments