2

I faced a situation where I need to upload files with size up to 1GB to my WebService. I use Spring and before I used MultipartFile for uploading files. But if we have endpoint like this:

//Spring annotations

    public void upload(MultipartFile file) {
       System.out.print("Hello world!");

    }

by the time thread reaches line with System.out.print("Hello world!"), all file is within the memory (JVM I mean) which may be a good option for small files, but not an option for files with 1GB size (if two users are trying to upload two files with 1GB size then we use 2GB RAM). Perhaps there is another way to handle such a situation with Spring?

Thanks, cheers, Andrey

Andrey Yaskulsky
  • 2,458
  • 9
  • 39
  • 81
  • Can you check this link and see whether this is what you are looking for - http://stackoverflow.com/questions/14615692/how-do-i-upload-stream-large-images-using-spring-3-2-spring-mvc-in-a-restful-way – aksappy Jun 23 '16 at 11:19
  • @aksappy thanks for the answer, unfortunately this is not exactly what I'm looking for; I'm looking for a way to upload 1GB files with no risk that JVM will fail because of OutOfMemorryError – Andrey Yaskulsky Jun 23 '16 at 11:28
  • 1
    See http://stackoverflow.com/questions/32782026/springboot-large-streaming-file-upload-using-apache-commons-fileupload – M. Deinum Jun 23 '16 at 11:37
  • @M.Deinum thanks for the answer, that's exactly that I was looking for – Andrey Yaskulsky Jun 23 '16 at 14:06

0 Answers0