Thanks Lukasz,

I'm not sure that is the issue. I did a simple verification test and added some 
debugging around the request content type I got the following :
Request Content Type: multipart/form-data; 
boundary=---------------------------22500187869113554433768726201
Using default regex string content type REGEX : true

I just plugged the default value into the REGEX parser :
Pattern multipartValidationPattern = 
Pattern.compile("^multipart/form-data(?:\\s*;\\s*boundary=[0-9a-zA-Z'()+_,\\-./:=?]{1,70})?(?:\\s*;\\s*charset=[a-zA-Z\\-0-9]{3,14})?");
boolean validContentType = request.getContentType() != null && 
multipartValidationPattern.matcher(contentType.toLowerCase(Locale.ENGLISH)).matches();

I tried to raise a ticket to include some logging in the isMultipartRequest 
function to record why it failed but I don't have an account anymore.

I will modify the source code locally to add some debug code this afternoon. 
Hopefully it will build OK and I can get back to you with some feedback.

Z.


On 1/3/2024, 5:19 pm, "Lukasz Lenart" <lukaszlen...@apache.org 
<mailto:lukaszlen...@apache.org>> wrote:


The request must match the following regex [1], more details in the
docs [2], yet I notice there is no logging around this logic, feel
free to create a ticket to improve that.


[1] 
https://github.com/apache/struts/blob/master/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java#L110
 
<https://github.com/apache/struts/blob/master/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java#L110>
[2] 
https://struts.apache.org/core-developers/file-upload.html#request-validation 
<https://struts.apache.org/core-developers/file-upload.html#request-validation>


śr., 28 lut 2024 o 23:28 Zoran Avtarovski <zo...@sparecreative.com 
<mailto:zo...@sparecreative.com>> napisał(a):
>
> Hi Guys,
>
>
>
> We are unable to upload files to our first 6.3 application using HTTP 
> requests, but the strange thing is they work with ajax requests. I suspect we 
> are overlooking something in the config which is required in 6.3.
>
>
>
> We are using 6.3.0.2 running on Tomcat 9. The file object is null after the 
> upload but we can see the upload is there.
>
>
>
> I can see the params interceptor finds the file and copies it to the temp 
> directory, but I then can’t access the file in the action??? What’s really 
> strange is if we use the same mechanism using a an ajax request with FormData 
> it works as expected. That’s why we created a simple setup as outlined below 
> to identify the root cause.
>
>
>
> Any help would really be appreciated.
>
>
>
> Here’s a snippet of the logs:
>
> multipart.JakartaMultiPartRequest (JakartaMultiPartRequest.java:103) - Found 
> file item: [upload]
>
> multipart.JakartaMultiPartRequest (JakartaMultiPartRequest.java:114) - Item 
> is a file upload
>
>
>
> When I try and access the file in my action:
>
> action.IndexAction (IndexAction.java:54) - Uploaded file : null
>
> action.IndexAction (IndexAction.java:55) - Uploaded file name : null
>
> action.IndexAction (IndexAction.java:56) - Uploaded file type : null
>
> action.IndexAction (IndexAction.java:57) - Uploaded file length : 0
>
>
>
>
>
> And then after the request has completed:
>
> multipart.JakartaMultiPartRequest (JakartaMultiPartRequest.java:361) - 
> Removing file upload name=Invoice - 1331-1.pdf, StoreLocation= 
> /apache-tomcat-9.0.44_base/work/Catalina/localhost/caams/upload_0569c990_d32c_4688_ad50_44db275ab0cc_00000000.tmp,
>  size=465396 bytes, isFormField=false, FieldName=upload
>
>
>
> This is what my form looks like:
>
>
>
> <s:form enctype="multipart/form-data" action="testUpload" method="post" 
> theme="simple">
>
> <s:file name="upload" key="file.to.upload" />
>
> <button type="submit" >Submit</button>
>
> </s:form>
>
>
>
> My action has the following (BaseAction extends ActionSupport):
>
>
>
> public class IndexAction extends BaseAction {
>
>
>
> private File upload;
>
> private String uploadFileName;
>
> private String uploadContentType;
>
> private long uploadContentLength;
>
>
>
> public IndexAction() {
>
> }
>
>
>
> @Override
>
> public String execute() {
>
> return SUCCESS;
>
> }
>
>
>
> public String edit() {
>
> return INPUT;
>
> }
>
>
>
> public String uploadTest() {
>
> try {
>
> LOGGER.debug("Uploaded file : "+ upload);
>
> LOGGER.debug("Uploaded file name : "+ uploadFileName);
>
> LOGGER.debug("Uploaded file type : "+ uploadContentType);
>
> LOGGER.debug("Uploaded file length : "+ uploadContentLength);
>
>
>
> inputStream = new FileInputStream(upload);
>
>
>
> if (inputStream != null) {
>
> inputStream.close();
>
> }
>
>
>
> } catch (Exception e) {
>
> LOGGER.error("General . uploading error :", e);
>
> }
>
>
>
> return SUCCESS;
>
> }
>
>
>
> public File getUpload() {
>
> return upload;
>
> }
>
>
>
> public void setUpload(File upload) {
>
> this.upload = upload;
>
> }
>
>
>
> public String getUploadFileName() {
>
> return uploadFileName;
>
> }
>
>
>
> public void setUploadFileName(String uploadFileName) {
>
> this.uploadFileName = uploadFileName;
>
> }
>
>
>
> public String getUploadContentType() {
>
> return uploadContentType;
>
> }
>
>
>
> public void setUploadContentType(String uploadContentType) {
>
> this.uploadContentType = uploadContentType;
>
> }
>
>
>
> public long getUploadContentLength() {
>
> return uploadContentLength;
>
> }
>
>
>
> public void setUploadContentLength(long uploadContentLength) {
>
> this.uploadContentLength = uploadContentLength;
>
> }
>
> }
>
>
>
> My relevant struts.xml config:
>
>
>
> <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
>
> <constant name="struts.i18n.encoding" value="UTF-8"/>
>
> <constant name="struts.devMode" value="false"/>
>
> <constant name="struts.locale" value="en_AU"/>
>
> <constant name="struts.ui.theme" value="simple"/>
>
> <constant name="struts.ui.templateDir" value="template"/>
>
>
>
> <constant name="struts.i18n.search.defaultbundles.first" value="true"/>
>
> <constant name="struts.ui.escapeHtmlBody" value="true"/>
>
>
>
> <!-- Max file size of 15mb -->
>
> <constant name="struts.multipart.maxSize" value="45000000" />
>
> <constant name="struts.multipart.maxStringLength" value="45000000" />
>
>
>
> <package name="spareTest" extends="default">
>
> <default-interceptor-ref name="paramsPrepareParamsStack"/>
>
>
>
> <action name="testUpload" class="indexAction" method="uploadTest">
>
> <result name="input" >/WEB-INF/pages/main/formUpload.jsp</result>
>
> <result name="success" type="redirectAction">home</result>
>
> </action>
>
>
>
> <action name="testFile" class="indexAction" method="edit">
>
> <result name="input" >/WEB-INF/pages/main/formUpload.jsp</result>
>
> </action>
>
>
>
> </package>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org 
<mailto:user-unsubscr...@struts.apache.org>
For additional commands, e-mail: user-h...@struts.apache.org 
<mailto:user-h...@struts.apache.org>







---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to