I want to upload a file to my web project, but I'm getting:
WARN o.a.struts2.dispatcher.Dispatcher - Could not find create multipart save directory '/temp'. WARN o.a.s.d.m.JakartaMultiPartRequest - Unable to parse request org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed.
/temp/upload_1e39874d_effe_405b_9a92_3050ca60a661_00000000.tmp
(No such file or directory)
so I want to change the upload directory
<struts>
<constant name="struts.multipart.saveDir" value="/tmp"></constant>
<package name="brand-struts" extends="abstract-struts">
<action name="saveBatchBrandGoodsInfo" class="brandgoodsAction"
method="saveBatchBrandGoodsInfo">
<interceptor-ref name="fileUpload">
<param name="savePath">/upload</param>
<param name="maximumSize">1024000</param>
</interceptor-ref>
<result name="data" type="json">
<param name="root">data</param>
</result>
</action>
</package>
</struts>
but it doesn't work, I keep getting the same error
AFAIK, there's no such thing as an abstract-struts
package. Just extend struts-default
and remove the savePath
customization.
You're including only the fileUpload Interceptor, not the whole defaultStack. You need to do:
<interceptor-ref name="defaultStack">
<param name="fileUpload.maximumSize">1024000</param>
</interceptor-ref>
Also ensure your form has enctype="multipart/form-data"
.