Skip to content

Commit

Permalink
fix: Image 업로드 시 dirName 필드를 제거한다. (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarltj authored Jan 8, 2024
1 parent 8402f5b commit cedf5da
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class ImageController {
private final ImageService imageService;

@PostMapping(consumes = {MULTIPART_FORM_DATA_VALUE, APPLICATION_JSON_VALUE})
public ImageResponse upload(@RequestPart("file") MultipartFile multipartFile, @ModelAttribute("dirName") String dirName) {
ImageResponse response = imageService.upload(multipartFile, dirName);
public ImageResponse upload(@RequestPart("file") MultipartFile multipartFile) {
ImageResponse response = imageService.upload(multipartFile);
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public interface ImageStorageHandler {

ImageResponse upload(File file, String dirName);
ImageResponse upload(File file);

void remove(String key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class NcpStorageHandler implements ImageStorageHandler{
private String bucket;

@Override
public ImageResponse upload(File file, String dirName) {
String key = generateRandomFileName(file, dirName);
public ImageResponse upload(File file) {
String key = generateRandomFileName(file);
String path = putImage(file, key);
removeFile(file);

Expand All @@ -46,8 +46,8 @@ public boolean doesObjectExists(String key) {
return amazonS3.doesObjectExist(bucket, key);
}

private String generateRandomFileName(File file, String dirName) {
return ROOT_DIRNAME + "/" + dirName + "/" + UUID.randomUUID().toString().substring(0, 8) + "-" + file.getName();
private String generateRandomFileName(File file) {
return ROOT_DIRNAME + "/" + UUID.randomUUID().toString().substring(0, 8) + "-" + file.getName();
}

private String putImage(File uploadFile, String fileName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class ImageService {

private final ImageStorageHandler imageStorageHandler;

public ImageResponse upload(MultipartFile multipartFile, String dirName) {
public ImageResponse upload(MultipartFile multipartFile) {
File file = convertMultipartFileToFile(multipartFile)
.orElseThrow();

return imageStorageHandler.upload(file, dirName);
return imageStorageHandler.upload(file);
}

public void remove(ImageDeleteRequest deleteRequest) {
Expand Down

0 comments on commit cedf5da

Please sign in to comment.