Skip to content

Commit

Permalink
Merge pull request #60 from mju-likelion/feature/zip-type-error-#59
Browse files Browse the repository at this point in the history
Feature/#59 윈도우 환경에서 zip 파일을 인식하지 못하는 문제
  • Loading branch information
Dh3356 authored Feb 18, 2024
2 parents 4cc8ca3 + 570e423 commit 0dc0668
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public class FileConstant {
public static final int MB = 1024 * 1024;
public static final int MAX_FILE_SIZE = MB * 10;
public static final String ZIP_CONTENT_TYPE = "application/zip";
public static final String X_ZIP_CONTENT_TYPE = "application/x-zip-compressed";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mjulikelion.bagel.util.annotaion.file.introduce;

import static org.mjulikelion.bagel.constant.FileConstant.MAX_FILE_SIZE;
import static org.mjulikelion.bagel.constant.FileConstant.X_ZIP_CONTENT_TYPE;
import static org.mjulikelion.bagel.constant.FileConstant.ZIP_CONTENT_TYPE;
import static org.mjulikelion.bagel.constant.FileConstant.ZIP_EXTENSION;
import static org.mjulikelion.bagel.constant.RegexPatterns.APPLICATION_STUDENT_ID_PATTERN;
Expand Down Expand Up @@ -39,13 +40,19 @@ private boolean isValidFileName(String fileName) {
}

private boolean isValidFileExtension(MultipartFile file) {
log.info("Is file extension valid? {}",
Objects.equals(file.getContentType(), ZIP_CONTENT_TYPE) && Objects.requireNonNull(
file.getOriginalFilename()).toLowerCase().endsWith(ZIP_EXTENSION));
return Objects.equals(file.getContentType(), ZIP_CONTENT_TYPE) && Objects.requireNonNull(
file.getOriginalFilename()).toLowerCase().endsWith(ZIP_EXTENSION);
String contentType = file.getContentType();
String filename = file.getOriginalFilename();

boolean isValidContentType =
Objects.equals(contentType, ZIP_CONTENT_TYPE) || Objects.equals(contentType, X_ZIP_CONTENT_TYPE);
boolean isValidFileExtension = filename != null && filename.toLowerCase().endsWith(ZIP_EXTENSION);

log.info("Is file extension valid? {}", isValidContentType && isValidFileExtension);

return isValidContentType && isValidFileExtension;
}


private boolean isValidFileSize(MultipartFile file) {
log.info("Is file size valid? {}", file.getSize() <= MAX_FILE_SIZE);
return file.getSize() <= MAX_FILE_SIZE;
Expand Down

0 comments on commit 0dc0668

Please sign in to comment.