Skip to content

Commit

Permalink
fix: CustomOutputStream 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
kariskan committed Aug 26, 2024
1 parent a8d742d commit 80cfab4
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,22 @@ public void handleFileUpload(HttpServletRequest request) throws Exception {
}
}

static class CustomOutputStream extends ByteArrayOutputStream {
@Override
public synchronized void reset() {
super.reset();
buf = new byte[32];
}
}

/**
* 클라이언트 요청을 buffer 단위로 읽어서 processBuffer 메소드를 호출합니다.
* processBuffer 메소드에서 헤더 파싱을 하고 boundary 체크를 하여 각 파트를 구분합니다.
*/
private void processMultipartData(InputStream inputStream, UploadContext context) throws Exception {
byte[] buffer = new byte[bufferSize];
ByteArrayOutputStream lineBuffer = new ByteArrayOutputStream();
ByteArrayOutputStream contentBuffer = new ByteArrayOutputStream();
ByteArrayOutputStream lineBuffer = new CustomOutputStream();
ByteArrayOutputStream contentBuffer = new CustomOutputStream();
PartContext partContext = new PartContext();
UploadState state = new UploadState();

Expand Down Expand Up @@ -389,7 +397,6 @@ ResponseEntity<InputStreamResource> download(@CheckField(FieldType.FILE_ID) @Pat
headers.add(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"" + encodedFileName + "\"; filename*=UTF-8''" + encodedFileName);


return ResponseEntity.ok()
.headers(headers)
.contentType(MediaType.APPLICATION_OCTET_STREAM)
Expand Down

0 comments on commit 80cfab4

Please sign in to comment.