220903_오답노트

백승한·2022년 9월 3일
0

오답노트

목록 보기
6/6

에러 해결 기록이 뒤죽박죽 이긴 한데,,ㅎㅎ
기록이 중요하니까 !

오늘의 에러 해결

No content length specified for stream data. Stream contents will be buffered in memory and could result in out of memory errors.

에러 원인

s3 업로드시 setContentLength 를 지정하지 않거나 IOUtils.toByteArray(inputStream) 사용시 inputStream 이 소진되어 발생하는 경고

해결 방법

setContentLength 을 지정하지 않아서 해당 블로그를 참고해서 수정했다.

metadata.setContentType(Mimetypes.getInstance().getMimetype(filename));

byte[] bytes = IOUtils.toByteArray(file.getInputStream());
metadata.setContentLength(bytes.length);

ByteArrayInputStream byteArrayIs = new ByteArrayInputStream(bytes);
            
PutObjectRequest por = new PutObjectRequest(bucket, filename, byteArrayIs, metadata)
                        .withCannedAcl(CannedAccessControlList.PublicRead);
amazonS3.putObject(por);            

AWS s3 upload source Tip

profile
방문해주셔서 감사합니다🙂

0개의 댓글