Thanks for sharing Mark!

Dream * Excel * Explore * Inspire
Jon McAlexander | Senior Infrastructure Engineer | Middleware/App Hosting | FHP 
| CTO | Wells Fargo Technology
8080 Cobblestone Rd | Urbandale, IA 50322 MAC: F4469-010  | +1 515 988 2508 | 
[email protected]<mailto:[email protected]>

Need to engage our teams?  Click here:
https://hop.cfapps.wellsfargo.net/mwae

This message may contain confidential and/or privileged information. If you are 
not the addressee or authorized to receive this for the addressee, you must not 
use, copy, disclose, or take any action based on this message or any 
information herein. If you have received this message in error, please advise 
the sender immediately by reply e-mail and delete this message. Thank you for 
your cooperation.

From: Mark Foley <[email protected]>
Sent: Monday, December 15, 2025 2:12 AM
To: [email protected]
Subject: Re: Migrating fileUpload




I found a solution:



Part fileUpload = request.getPart("newFile");

contentType = fileUpload.getContentType();



This gives me the string values as expected: "image/jpeg", "image/gif", 
"image/png", etc.



--Mark



-----Original Message-----

Date: Sun, 14 Dec 2025 21:55:51 -0500

Organization: Novatec Software Engineering, LLC

To: [email protected]<mailto:[email protected]>

Subject: Migrating fileUpload

From: Mark Foley <[email protected]<mailto:[email protected]>>



I'm still in the process of migrating my tomcat 8.5.11 to 10.1.13. So for so

good with the help of Christopher Schultz and others on this list. Thanks.



My next challenge is migrating the 8.5 apps using org.apache.commons.fileupload

to jakarta.servlet.annotation.MultipartConfig.



I've got it partially working. One problem is determining the content type of

the uploaded file. In my code I have:



    Part fileUpload = request.getPart("newFile");



    if (fileUpload != null)

    {

        fileUpload.write("boogaPhoto");

        Path filePath = Paths.get("/tmp/boogaPhoto");

        contentType = Files.probeContentType(filePath);

              :



The problem is that the content type comes back null. But ...



$ file /tmp/boogaPhoto

/tmp/boogaPhoto: JPEG image data, JFIF standard 1.02, resolution (DPI), density 
72x72, segment length 16, baseline, precision 8, 186x253, components 3



The old:



    contentType = (fileItem).getContentType();



    if (contentType.compareToIgnoreCase("image/jpeg") == 0) suffix = ".jpg";

    else if (contentType.compareToIgnoreCase("image/gif") == 0) suffix = ".gif";

    else if (contentType.compareToIgnoreCase("image/png") == 0) suffix = ".png";



did return a usable content type.



How do I do this with "new" java.nio.file classes ... or is there a better way?



Thanks --Mark



---------------------------------------------------------------------

To unsubscribe, e-mail: 
[email protected]<mailto:[email protected]>

For additional commands, e-mail: 
[email protected]<mailto:[email protected]>





---------------------------------------------------------------------

To unsubscribe, e-mail: 
[email protected]<mailto:[email protected]>

For additional commands, e-mail: 
[email protected]<mailto:[email protected]>


Reply via email to