0

spring's org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile#getBytes do additional copy of underlying stream from Part.

form-data -> DiskFileItem -> Spring's copy

        @Override
        public byte[] getBytes() throws IOException {
            return FileCopyUtils.copyToByteArray(this.part.getInputStream());
        }

org.springframework.web.multipart.commons.CommonsMultipartFile#getBytes

form-data -> FileItem -> no copy

    @Override
    public byte[] getBytes() {
        if (!isAvailable()) {
            throw new IllegalStateException("File has been moved - cannot be read again");
        }
        byte[] bytes = this.fileItem.get();
        return (bytes != null ? bytes : new byte[0]);
    }

It appears that CommonsMultipartFile has a smaller memory footprint compared to other options, however, it is important to note that it will soon be deprecated.

Could you explain the reason behind this?

From a performance perspective, is it recommended to use CommonsMultipartFile?

bug_lee
  • 1
  • 1

0 Answers0