Skip to content

Commit

Permalink
Merge pull request #305 from GSM-MSG/304-signup-image-upload-expander…
Browse files Browse the repository at this point in the history
…-inspection

🔀 :: 회원가입시 이미지 확장자 검사 로직
  • Loading branch information
Umjiseung authored Mar 26, 2024
2 parents 3884b78 + 2e2610d commit 081aea2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AuthController(
}

@PatchMapping("/password")
fun updatePassword(@RequestBody updatePasswordRequestDto: UpdatePasswordRequestDto): ResponseEntity<Void> {
fun updatePassword(@RequestBody @Valid updatePasswordRequestDto: UpdatePasswordRequestDto): ResponseEntity<Void> {
updatePasswordService.execute(updatePasswordRequestDto)
return ResponseEntity.noContent().build()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.msg.gauth.domain.auth.service

import com.msg.gauth.domain.admin.exception.FileExtensionInvalidException
import com.msg.gauth.domain.auth.presentation.dto.response.SignUpImageResDto
import com.msg.gauth.domain.email.exception.AuthCodeExpiredException
import com.msg.gauth.domain.email.exception.AuthCodeNotVerificationException
Expand All @@ -23,6 +24,6 @@ class SignUpImageUploadService(
if(previousUrl != null)
s3Util.deleteImage(previousUrl)

return SignUpImageResDto(s3Util.upload(image))
return SignUpImageResDto(s3Util.imageUpload(image))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,7 @@ class UploadImageService(
private val s3Util: S3Util
) {
fun execute(image: MultipartFile): UploadImageResDto {
val list = listOf("jpg", "jpeg", "png", "gif")

val splitFile = image.originalFilename.toString().split(".")

if(splitFile.size < 2)
throw FileExtensionInvalidException()

val extension = splitFile[1].lowercase()

if(list.none { it == extension })
throw FileExtensionInvalidException()

val imgURL = s3Util.upload(image)
val imgURL = s3Util.imageUpload(image)

return UploadImageResDto(imgURL)
}
Expand Down
20 changes: 19 additions & 1 deletion src/main/kotlin/com/msg/gauth/global/thirdparty/aws/s3/S3Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.msg.gauth.global.thirdparty.aws.s3

import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.model.ObjectMetadata
import com.msg.gauth.domain.admin.exception.FileExtensionInvalidException
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import org.springframework.web.multipart.MultipartFile
Expand All @@ -13,7 +14,24 @@ class S3Util(
){
@Value("\${cloud.aws.s3.bucket}")
private val bucket: String? = null
fun upload(file: MultipartFile): String {

fun imageUpload(image: MultipartFile): String {
val list = listOf("jpg", "jpeg", "png", "gif")

val splitFile = image.originalFilename.toString().split(".")

if(splitFile.size < 2)
throw FileExtensionInvalidException()

val extension = splitFile[1].lowercase()

if(list.none { it == extension })
throw FileExtensionInvalidException()

return upload(image)
}

private fun upload(file: MultipartFile): String {
val profileName = "${bucket}/${UUID.randomUUID()}${file.originalFilename}"
val metadata = ObjectMetadata()
metadata.contentLength = file.inputStream.available().toLong()
Expand Down

0 comments on commit 081aea2

Please sign in to comment.