Closed 9oj0e closed 2 months ago
메뉴 등록
메뉴 목록보기
파일 업로드 모듈화 (MultiPart, base64)
public static String fileUpload(MultipartFile file, int id) { // UUID_식별자 번호_파일 이름.확장자 (id = storeId / userId) String newFilename = UUID.randomUUID() + "_" + id + "_" + file.getOriginalFilename(); Path newFilePath = Paths.get("./upload/" + newFilename); try { Files.write(newFilePath, file.getBytes()); } catch (IOException e) { throw new Exception400("잘못된 요청입니다."); } return newFilename; // 생성된 파일 이름 return }
public static String base64Upload(String encodedData, String name, String extension) { // UUID_파일 이름.확장자 (파일 이름 = 사용자 이름) String newFilename = UUID.randomUUID() + "_" + name + "." + extension; Path newFilePath = Paths.get("./upload/" + newFilename); try { byte[] decodedByte = Base64.getDecoder().decode(encodedData); Files.write(newFilePath, decodedByte); } catch (IOException e) { throw new Exception400("잘못된 요청입니다."); } return newFilename; // 생성된 파일 이름 return }
public static String getFilePath(String filename) { return "/upload/" + filename; // 파일 경로 return }
업데이트
메뉴 등록
메뉴 목록보기
파일 업로드 모듈화 (MultiPart, base64)
파일 업로드 모듈 1 (MultiPart)
파일 업로드 모듈 2 (base64)
파일 경로 모듈