How to get file name from HttpServletRequest

You can use the below java method which returns the file name from part

private String getFileName(Part part) {
for (String content : part.getHeader(“content-disposition”).split(“;”)) {
if (content.trim().startsWith(“filename”)) {
return content.substring(content.indexOf(‘=’) + 1).trim().replace(“\””, “”);
}

}
return null;
}

Leave a Reply

Your email address will not be published. Required fields are marked *