-
Notifications
You must be signed in to change notification settings - Fork 20
[신민경] 웹 서버 step 7 구현 (2) #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shinminkyoung1
wants to merge
35
commits into
softeerbootcamp-7th:shinminkyoung1
Choose a base branch
from
shinminkyoung1:task3-2
base: shinminkyoung1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[신민경] 웹 서버 step 7 구현 (2) #221
shinminkyoung1
wants to merge
35
commits into
softeerbootcamp-7th:shinminkyoung1
from
shinminkyoung1:task3-2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
완료 작업 목록
웹 서버 7단계 - 이미지 업로드 구현
HttpRequest에서multipart/form-data바디 파싱 로직 추가./uploads)에 저장ARTICLE테이블에 이미지 파일 경로(imagePath) 컬럼 추가/uploads/경로로 들어오는 GET 요청에 대해 실제 이미지 파일 응답User테이블에 프로필 이미지 경로 추가index.html및mypage.html에서 저장된 경로를 이용해 이미지 출력주요 고민과 해결 과정
→ 헤더는 BufferReader로 읽고, 바디(파일 데이터 포함)는 InputStream에서 바이트 단위로 직접 읽도록 구조 변경
파일명 중복 방지와 저장 경로 설정을 어떻게 해결하는가
→ 여러 사용자가 동시에 image.jpg라는 파일을 올려도 덮어씌워지지 않도록 UUID를 활용해 고유한 이름 부여
스트림 읽기 충돌 에러 발생
상황 분석
HttpRequest 생성자에서 BufferdReader를 생성하여 헤더를 읽으면, BufferedReader을 위해 바디 데이터의 일부까지 미리 읽어 자신의 내부 버퍼에 넣음
그 상태에서 in.readNBytes(contentLength)를 호출하면, 이미 버퍼로 들어간 앞부분 데이터는 건너뛰게 되어 데이터 불일치가 발생하고 소켓 연결이 꼬임
→ HttpRequest를 바이트 단위로 직접 제어하도록 수정
⇒ 스트림 읽기 방식 변경
InputStream에서 1바이트씩 읽어 한 줄(String)을 만듦
BufferedReader의 버퍼링 문제 해결 위함
HttpRequest.java정리)
바이너리 스트림 제어
BufferedReader를 제거하고InputStream을 직접 제어하여 헤더는 텍스트로, 바디는 순수 바이트로 읽는readLine과parseBody로직을 구현멀티파트 파서 구현
multipart/form-data규격에 맞춰boundary를 기준으로 데이터를 쪼개 텍스트와 파일을 구분하는 로직을HttpRequestUtils에 추가AI에 도움받은 부분
→ AppConfig에서 마이페이지에 대한 정적 파일 연결을 제외하지 않아서 발생했던 문제였음