Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix original file upload to use actual file name rather than uploadxxx.tmp #893

Conversation

gregh3269
Copy link
Contributor

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.

@@ -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()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the same is on 6.xx, see here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lukaszlenart lukaszlenart self-requested a review March 8, 2024 08:05
@lukaszlenart lukaszlenart merged commit 4939d3c into apache:release/struts-7-0-x Mar 8, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants