πŸ”§ API_

πŸ–ΌοΈ CKEditor5λ₯Ό Spring Boot에 μ μš©ν•œ 기둝 – 이미지 μ—…λ‘œλ“œ κ²Œμ‹œνŒ κ΅¬ν˜„κΈ°

CodeLoge 2025. 5. 27. 21:24

πŸ”Ή 1. 에디터 μ»€μŠ€ν„°λ§ˆμ΄μ§• λͺ©μ 

 

1️⃣ κ²Œμ‹œκΈ€ μž‘μ„± 쀑 이미지 직접 μ—…λ‘œλ“œ κΈ°λŠ₯ 제곡
2️⃣ μ—λ””ν„°μ—μ„œ <img> νƒœκ·Έ μ‚½μž…κΉŒμ§€ μ‹€μ‹œκ°„ μžλ™ 처리
3️⃣ μ‚¬μš©μž UX 쀑심 μž‘μ„± ν™˜κ²½ κ΅¬ν˜„


πŸ”Ή 2. μ—…λ‘œλ“œ μ„œλ²„ ꡬ쑰 (Java/Spring)

 

πŸ“Œ μ»¨νŠΈλ‘€λŸ¬ 경둜

• POST /boardCombo/CKEditor5/uploadImage

• GET /boardCombo/CKEditor5/loadImage

 

πŸ“Œ μ—…λ‘œλ“œ 처리 흐름

 

βœ… MultipartFile μˆ˜μ‹ 
βœ… UUID 기반 고유 파일λͺ… 생성
βœ… upload.path κ²½λ‘œμ— μ €μž₯
βœ… 이미지 URL λ°˜ν™˜ (/loadImage?name=...)

 

πŸ“Œ μ΄λ―Έμ§€ 뢈러였기 처리

 

βœ… μ €μž₯된 κ²½λ‘œμ—μ„œ 파일 쑰회
βœ… Files.probeContentType() → MIME νƒ€μž… μ„€μ •
βœ… byte[] 둜 응닡


πŸ”Ή 3. μ„œλ²„ 경둜 μ„€μ • 뢄리

 

πŸ“Œ @ConfigurationProperties μ‚¬μš©

@ConfigurationProperties(prefix = "upload")
public class CKEditor5ImgUploadConfig {
  private String path;
}

πŸ“Œ application.properties μ˜ˆμ‹œ

upload.path=/usr/local/ckeditor/upload/

πŸ”Ή 4. JS μ»€μŠ€ν„°λ§ˆμ΄μ§• – 에디터 연동

 

1️⃣ FileRepository.createUploadAdapter μž¬μ •μ˜
2️⃣ fetch()둜 이미지 POST 전솑
3️⃣ μ‘λ‹΅λœ url을 { default: url } ν˜•νƒœλ‘œ CKEditor에 μžλ™ μ‚½μž…

 

πŸ“Œ μ—λŸ¬ 처리 흐름

 

βœ… 413 (Payload too large) → SweetAlert μ•Œλ¦Ό
βœ… μ„œλ²„ 였λ₯˜ λ°œμƒ μ‹œ → μ—λŸ¬ λ©”μ‹œμ§€ + μ‚¬μš©μž κ²½κ³ 


πŸ”Ή 5. 에디터 μ‚¬μš© 방식 (updateBoard.js)

 

1️⃣ editor.getData()둜 HTML μ½˜ν…μΈ  μΆ”μΆœ
2️⃣ Ajax 전솑 μ‹œ updateBoardTitle, updateBoardContent ν•¨κ»˜ 전솑
3️⃣ 등둝 성곡 μ‹œ → κ²Œμ‹œνŒμœΌλ‘œ λ¦¬λ‹€μ΄λ ‰μ…˜


πŸ”Ή 6. JSP ν™”λ©΄ 적용

 

1️⃣ textareaλ₯Ό ClassicEditor둜 λ³€ν™˜
2️⃣ .ck-editor__editable CSS μ„€μ • (높이 μ§€μ •)
3️⃣ 등둝 λ²„νŠΌ 클릭 μ‹œ updateBoard() μ‹€ν–‰

 

πŸ’‘ μ΅œμ’… μš”μ•½

 

βœ… 이미지 μ—…λ‘œλ“œ μš”μ²­ μˆ˜μ‹  → UUID μ €μž₯ → URL 응닡
βœ… CKEditor λ‚΄ μ»€μŠ€ν„°λ§ˆμ΄μ§• μ–΄λŒ‘ν„°λ‘œ 이미지 μ‚½μž… μžλ™ν™”
βœ… SweetAlert둜 μ‚¬μš©μž 쀑심 μ—λŸ¬ λŒ€μ‘
βœ… HTML/CSS/JS 완성도 높은 연동