0

While trying to upload the Image in struts2 the image is not uploading and showing following msg Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.tempdir

user1327216
  • 43
  • 1
  • 5

2 Answers2

2

This is manual configuration, Once the file uploaded you have to explicitly handle to save the file(due to security reasons server delete the file immediately.)

import org.apache.commons.io.FileUtils;

String fullFileName = "d:/temp/"+uploadFileName;

File destFile = new File(fullFileName);

FileUtils.copyFile(upload, destFile);

Source : FileUpload

You can configure it in struts.properties file

struts.multipart.saveDir - The directory where the uploaded files will be placed. If this property is not set it defaults to javax.servlet.context.tempdir.

put the uploaded files in /tmp. My application will move them to their final destination

 struts.multipart.saveDir=/tmp
MohanaRao SV
  • 1,117
  • 1
  • 8
  • 22
2

You are getting this message due to build din feature of S2.you need to tell S2 file upload interceptor where you want to place the uploaded file using struts.multipart.saveDir property either in the struts.property file or as a constant in struts.xml file like

Struts property file

struts.multipart.saveDir=location of your choice

struts.xml file

<constant name="struts.multipart.saveDir" value="your location" />

If this property is not set it defaults to javax.servlet.context.tempdir.Sine S2 put the upload file in the temp directory in case you have not specified the saveDir but once the process complete, in order for the clean up process it will remove that temp file, so make sure either you have set the saveDir parameter or you should put logic in your action class to pick file from there and move it to your choice location.

For details about S2 file upload read the official doc

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
  • can you help me out in this one ? [not delete .tmp file](http://stackoverflow.com/questions/19543422/how-to-delete-tmp-file-in-fileupload-struts2) – HybrisHelp Oct 24 '13 at 05:56