Mark,
On 12/15/25 3:11 AM, Mark Foley wrote:
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.
Be aware that the client can lie to you.
-chris
-----Original Message-----
Date: Sun, 14 Dec 2025 21:55:51 -0500
Organization: Novatec Software Engineering, LLC
To: [email protected]
Subject: Migrating fileUpload
From: Mark Foley <[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]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]