You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@struts.apache.org by "gregh3269 (via GitHub)" <gi...@apache.org> on 2024/03/07 06:22:08 UTC

[PR] Fix original file upload to use actual file name rather than uploadxxx.tmp [struts]

gregh3269 opened a new pull request, #893:
URL: https://github.com/apache/struts/pull/893

   Testing the original file upload and it now does not work.
   
   I get an error where its using the wrong file name ie upload5549a568d9794ef5b654da83d079613500000045.tmp rather than the
   actual file name.  This fixes the original upload.
   
   I also modified one of my uploads to use the UploadedFilesAware.  To get the original file name to save on the server I use
   
   ```
   for (int i = 0; i < uploads.size(); i++) {
       String fileName = uploads.get(i).getOriginalName();
       ....
   }
   ```
   The method getOriginalName() text says "original file name from upload source" so it looks correct.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@struts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix original file upload to use actual file name rather than uploadxxx.tmp [struts]

Posted by "lukaszlenart (via GitHub)" <gi...@apache.org>.
lukaszlenart commented on code in PR #893:
URL: https://github.com/apache/struts/pull/893#discussion_r1517363676


##########
core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java:
##########
@@ -337,7 +337,7 @@ public UploadedFile<T>[] getFile(String fieldName) {
      */
     public String[] getFileNames(String fieldName) {
         return uploadedFiles.getOrDefault(fieldName, Collections.emptyList()).stream()
-                .map(file -> getCanonicalName(file.getName()))
+                .map(file -> getCanonicalName(file.getOriginalName()))

Review Comment:
   I think I found where this bug comes from, Commons `FileItem.getName()` returns:
   
   > Returns the original filename in the client's filesystem, as provided by the browser (or other client software)
   
   and `UploadedFile.getName()` returns name of the uploaded file on the server side, so you are right.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@struts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix original file upload to use actual file name rather than uploadxxx.tmp [struts]

Posted by "lukaszlenart (via GitHub)" <gi...@apache.org>.
lukaszlenart commented on code in PR #893:
URL: https://github.com/apache/struts/pull/893#discussion_r1517360459


##########
core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java:
##########
@@ -337,7 +337,7 @@ public UploadedFile<T>[] getFile(String fieldName) {
      */
     public String[] getFileNames(String fieldName) {
         return uploadedFiles.getOrDefault(fieldName, Collections.emptyList()).stream()
-                .map(file -> getCanonicalName(file.getName()))
+                .map(file -> getCanonicalName(file.getOriginalName()))

Review Comment:
   But the same is on 6.xx, see [here](https://github.com/apache/struts/blob/master/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaMultiPartRequest.java#L268)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@struts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix original file upload to use actual file name rather than uploadxxx.tmp [struts]

Posted by "lukaszlenart (via GitHub)" <gi...@apache.org>.
lukaszlenart merged PR #893:
URL: https://github.com/apache/struts/pull/893


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@struts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org