Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File storage in Spring

I would like to save files uploaded from a form to certain folder in my Spring 3 application. I'm a rookie with this, don't know how to get started. Files must be java File format.

like image 949
mjgirl Avatar asked Dec 13 '25 22:12

mjgirl


2 Answers

Here's how you can define the absolute path to a temporary directory using System Properties and Spring Expression Language:

<!-- package shortened for readability -->
<bean id="multipartResolver"
      class="org.springframework....CommonsMultipartResolver">
    <property name="uploadTempDir"
      value="#{ systemProperties['java.io.tmpdir'] }/yourwebapp/upload"/>
</bean>

Reference:

  • System Properties and Spring Expression Language
  • System.getProperties() (includes reference for java.io.tmpdir)
like image 154
Sean Patrick Floyd Avatar answered Dec 16 '25 12:12

Sean Patrick Floyd


Use Spring's FileUpload support, it's fully documented, with examples.

like image 37
skaffman Avatar answered Dec 16 '25 11:12

skaffman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!