File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
src/main/kotlin/gogo/gogostage/domain/image/application Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -8,16 +8,21 @@ import org.springframework.web.multipart.MultipartFile
88class ImageValidator {
99
1010 fun validImage (image : MultipartFile ) {
11- val list = listOf (" jpg" , " png" , " gif" )
12- val splitFile = image.originalFilename.toString().split( " . " )
11+ val allowedExtensions = listOf (" jpg" , " png" , " gif" )
12+ val maxFileSize = 10 * 1024 * 1024
1313
14- if (splitFile.size != 2 )
15- throw StageException (" Image Extension Invalid" , 400 )
14+ val fileName = image.originalFilename ? : throw StageException (" No file name" , 400 )
1615
17- val extension = splitFile[ 1 ] .lowercase()
16+ val extension = fileName.substringAfterLast( ' . ' , missingDelimiterValue = " " ) .lowercase()
1817
19- if (list.none { it == extension })
18+ if (extension.isBlank() || extension !in allowedExtensions) {
2019 throw StageException (" Image Extension Invalid" , 400 )
20+ }
21+
22+ if (image.size >= maxFileSize) {
23+ throw StageException (" Image Size Exceeds 10MB" , 400 )
24+ }
2125 }
2226
27+
2328}
You can’t perform that action at this time.
0 commit comments