Skip to content

Commit

Permalink
Merge pull request #99 from everymeals/feature/get-s3-muti-url
Browse files Browse the repository at this point in the history
refactor : 이미지 업로드 갯수 request 추가
  • Loading branch information
Qbeom0925 authored Feb 20, 2024
2 parents 41d540a + 5244eb4 commit b0fa925
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -36,20 +40,34 @@ public class S3Controller {
4. Url에 PutMapping 이미지 파일을 binary로 보낼 경우, S3에 저장됩니다.
PS. Server에는 ImageKey로만 통신합합니다.
""")
public ApplicationResponse<S3GetResignedUrlRes> getPresignedUrl(
public ApplicationResponse<List<S3GetResignedUrlRes>> getPresignedUrl(
@RequestParam(value = "fileDomain")
@Schema(
title = "파일 도메인",
defaultValue = "store",
example = "store",
description = "store, meal, user 중 하나를 입력해주세요.",
allowableValues = {"store", "meal", "user"})
String fileDomain) {
String fileName = UUID.randomUUID().toString();
fileName = fileDomain + File.separator + fileName;
URL test = s3Util.getPresignedUrl(fileName);
return ApplicationResponse.ok(
S3GetResignedUrlRes.builder().imageKey(fileName).url(test.toString()).build());
String fileDomain,
@Min(value = 1, message = "최소 1개 이상의 파일을 업로드해주세요.")
@Max(value = 10, message = "최대 10개까지 업로드 가능합니다.")
@RequestParam(value = "count")
@Schema(
title = "파일 개수",
defaultValue = "1",
example = "1",
description = "파일 개수를 입력해주세요. 최대 10개까지 업로드 가능합니다.")
Integer count) {
List<S3GetResignedUrlRes> res = new ArrayList<>();
for (int i = 0; i < count; i++) {
String fileName = UUID.randomUUID().toString();
fileName = fileDomain + File.separator + fileName;
URL url = s3Util.getPresignedUrl(fileName);
S3GetResignedUrlRes build =
S3GetResignedUrlRes.builder().imageKey(fileName).url(url.toString()).build();
res.add(build);
}
return ApplicationResponse.ok(res);
}

@Operation(
Expand Down

0 comments on commit b0fa925

Please sign in to comment.