get the extension of the uploaded file in jsp using apache common fileupload
-
22-04-2021 - |
Domanda
Initially i started with storing the images in database for security and easy backup purpose.
so i never faced the problems to get the extension of the file.
Now i am facing problem because database load.
So i planned that i will store the images in a folder and i will show those images.
but i need to rename those file and store the extension in database so that i can directly access.
But as i was string the images in database, i never cared about the extension of the file.
As i have to access the image file, i must know the extension.
How to get the extension of the file in Apache common fileupload.
Soluzione
Here is how I have done it in my code. item is a FileItem or a FileItemStream object.
String format = "none";
String fileName = item.getName();
int index = fileName.lastIndexOf(".");
if(index > 0){
format = fileName.substring(index+1);
format = format.toLowerCase();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow