Skip to content

Commit

Permalink
feat: 파일 업로드 에러 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
km2535 committed Dec 5, 2024
1 parent 07b5a0b commit 8539c86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Objects;

import org.badminton.api.common.exception.EmptyFileException;
import org.badminton.api.common.exception.FileSizeOverException;
Expand Down Expand Up @@ -37,13 +36,17 @@ public String uploadFile(MultipartFile uploadFile, String uuid) {
if (uploadFile.getSize() > MAX_FILE_SIZE) {
throw new FileSizeOverException(uploadFile.getSize());
}
log.info("upload : {}", uploadFile.getName());
// if (uploadFile.isEmpty() || Objects.isNull(uploadFile.getOriginalFilename())) {
// throw new EmptyFileException();
// }
log.info("upload validate 이후 : {}", uploadFile.getName());

if (uploadFile.isEmpty() || Objects.isNull(uploadFile.getOriginalFilename())) {
throw new EmptyFileException();
}
try {
String fileExtension = getFileExtension(uploadFile.getOriginalFilename());
byte[] processedImage = processImage(uploadFile, fileExtension);
log.info(" try processedImage : {}", processedImage);

String newFileExtension = determineNewFileExtension(fileExtension);
String fileName = makeFileName(newFileExtension, uuid);

Expand All @@ -54,6 +57,7 @@ public String uploadFile(MultipartFile uploadFile, String uuid) {
s3Client.putObject(new PutObjectRequest(bucket, fileName,
new ByteArrayInputStream(processedImage), objectMetadata)
.withCannedAcl(CannedAccessControlList.PublicRead));
log.info(" s3Client 실행 : {}", fileName);

return toCloudFrontUrl(s3Client.getUrl(bucket, fileName).toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
public class ImageConversionService {

public byte[] convertToWebP(MultipartFile file) {
log.info("try 시작 전");
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
InputStream inputStream = file.getInputStream()) {

log.info("try 시작");
ImmutableImage image = ImmutableImage.loader().fromStream(inputStream);
log.info("try 시작");
WebpWriter writer = WebpWriter.DEFAULT;

ImageMetadata metadata = ImageMetadata.empty;
log.info("metadata 후");

writer.write(image, metadata, outputStream);
log.info("writer.write 후");

return outputStream.toByteArray();
} catch (IOException exception) {
Expand Down

0 comments on commit 8539c86

Please sign in to comment.