Will Spring contain content in memory or store on disk?

When the file says that the size of 100 MB downloaded from the browser, Spring will store the whole data in memory or temporarily store it on disk. After going through the Spring doc, I know how to set up a temporary directory, but I want to know what will happen if I don't mention it.

Having the following declaration:

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> 

Bean:

 public class FileHolder { private MultipartFile file; public void setFile(MultipartFile file) { this.file = file; } public MultipartFile getFile() { return file; } } 

Will the file object in the bean above contain 100 MB of data?

+7
java spring-mvc apache-commons-fileupload
source share
3 answers

A bit more digging in javadoc shows that the default maximum memory size is 10,240 bytes. From this, I assume that any download less than 10 KB is stored in memory, something more will be stored on the disk. If you do not specify the location of the disk, it will most likely use the default value (I would assume that it will use the default tmp system directory).

+10
source share

If you have not set the temp directory CommonsMultipartResolver , it will save the temporary files in the temporary directory of the servlet container.

The file object in your example does not contain data similar to the java.io.File link. You need to get the data using file.getBytes() .

+2
source share

Yes, but if it is stored on disk, it will be deleted after processing the request. You can set the threshold when it will be saved to disk:

In the definition of multipartresolver bean, for example:

 <property name="maxUploadSize" value="1000000" /> <property name="maxInMemorySize" value="1000" /> 

If it is stored in memory, you can save it in the session and process it in the next request, for example, for example, if you are waiting for user confirmation.

+2
source share

All Articles