NOT FOUND

response because it is invalid java.lang.IllegalArgumentException: The Unicode character 본문

spring boot

response because it is invalid java.lang.IllegalArgumentException: The Unicode character

이종은 2024. 8. 8. 12:13
The HTTP response header [Content-Disposition] with value [attachment; filename="
과제 제출.zip"] has been removed from the response because it is invalid java.lang.IllegalArgumentException: The Unicode character [과] at code point [44,284] cannot be encoded as it is outside the permitted range of 0 to 255

 

zip 파일 다운로드 중 

StreamUtils.copy(fis, zipOut); 부분에서 에러가 발생했다.

 

response 헤더 부분에서 한글을 사용해서 나는 에러였다. (디버그 시 copy에서 에러가 나지만)

response.addHeader("Content-Disposition", "attachment; filename=\"과제 제출.zip\"");

 

response.addHeader("Content-Disposition", "attachment; filename*=UTF-8''" + URLEncoder.encode(zipFileName+".zip",
                                                                                              StandardCharsets.UTF_8).replace("+", "%20"));

 

 

 

위와 같이 utf-8로 인코딩 해주면 된다.

replace는 띄어쓰기가 크롬에서 + 로 그대로 출력되어서 +의 경우 %20으로 변경하도록 한것.