Skip to content

Commit

Permalink
⚡ : 관리자 페이지 일부 기능 구현(#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
imenuuu committed May 5, 2024
1 parent 9ab5448 commit b0c00fd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 92 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/example/runway/dto/user/UserRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,6 @@ public static class DashBoardDto {
@AllArgsConstructor
@NoArgsConstructor
public static class UserInfoDto {
private int userId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public class AwsS3ServiceImpl implements AwsS3Service{
public String upload(MultipartFile multipartFile,String dirName) throws ForbiddenException, IOException {
String fileName = dirName+"/"+UUID.randomUUID().toString() + ".jpg";

//MultipartFile resizeFile=resizeImage(fileName,multipartFile.getContentType().substring(multipartFile.getContentType().lastIndexOf("/") + 1),multipartFile,600);

byte[] bytes = multipartFile.getBytes();

ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
Expand Down Expand Up @@ -132,96 +130,6 @@ public String getFileExtensions(String fileName) throws ForbiddenException {
throw new ForbiddenException(WRONG_FORMAT_FILE);
}
}


private static class CustomMultipartFile implements MultipartFile {
private final String name;

private final String originalFilename;

private final String contentType;

private final byte[] content;
boolean isEmpty;


public CustomMultipartFile(String name, String originalFilename, String contentType, byte[] content) {
Assert.hasLength(name, "Name must not be null");
this.name = name;
this.originalFilename = (originalFilename != null ? originalFilename : "");
this.contentType = contentType;
this.content = (content != null ? content : new byte[0]);
this.isEmpty = false;
}

@Override
public String getName() {
return this.name;
}

@Override
public String getOriginalFilename() {
return this.originalFilename;
}

@Override
public String getContentType() {
return this.contentType;
}

@Override
public boolean isEmpty() {
return (this.content.length == 0);
}

@Override
public long getSize() {
return this.content.length;
}

@Override
public byte[] getBytes() throws IOException {
return this.content;
}

@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(this.content);
}

@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
FileCopyUtils.copy(this.content, dest);
}
}

public String upload(MultipartFile file,String dirName) throws ForbiddenException, IOException {
String fileName = null;
try {
fileName = dirName + "/" + createFileNames(file.getOriginalFilename());
} catch (ForbiddenException e) {
throw new ForbiddenException(FAIL_UPLOAD_IMG);
}
System.out.println(fileName);

byte[] bytes = new byte[0];
try {
bytes = file.getBytes();
// Convert the image to jpg
} catch (IOException e) {
throw new ForbiddenException(FAIL_UPLOAD_IMG);
}

ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(bytes.length);
objectMetadata.setContentType("image/jpeg"); // Set content type to jpeg

amazonS3.putObject(new PutObjectRequest(bucket, fileName, new ByteArrayInputStream(bytes), objectMetadata));


return amazonS3.getUrl(bucket, fileName).toString();
}

private String getImageUrl(String fileName){
return url + "/" + fileName;
}
Expand Down

0 comments on commit b0c00fd

Please sign in to comment.