Skip to content

Commit

Permalink
Fix: 게시물 등록 이미지 url(객체X) (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
dainshon authored Jul 29, 2024
1 parent 73bf94b commit 1057a49
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/inandout/backend/service/myroom/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class S3Service {
@Value("${spring.cloud.aws.s3.bucket}")
private String bucket;

private String location = "ap-northeast-2";

private final AmazonS3 s3Client;

public List<String> uploadFile(List<MultipartFile> multipartFile) {
Expand All @@ -38,13 +40,15 @@ public List<String> uploadFile(List<MultipartFile> multipartFile) {
System.out.println("fileName: "+fileName);
System.out.println("fileNametype: "+file.getContentType());

String image_url = "https://"+bucket+".s3."+location+".amazonaws.com/"+fileName;

try(InputStream inputStream = file.getInputStream()) {
s3Client.putObject(new PutObjectRequest(bucket, fileName, inputStream, objectMetadata)
.withCannedAcl(CannedAccessControlList.PublicRead));
} catch(IOException e) {
throw new RuntimeException("uploadFile 오류");
}
fileNameList.add(fileName);
fileNameList.add(image_url);
});

return fileNameList;
Expand All @@ -71,6 +75,7 @@ private String getFileExtension(String fileName) {
if (!fileValidate.contains(idxFileName)) {
return "파일 잘못된 형식";
}

return fileName.substring(fileName.lastIndexOf("."));
}

Expand Down

0 comments on commit 1057a49

Please sign in to comment.