EN
Spring Boot 2 - get MIME Type by file extension
7
points
In this short article, we would like to show how in Spring Boot 2 get MIME Type when we know file extension.
Quick solution:
// import org.springframework.boot.web.server.MimeMappings;
String mimeType = MimeMappings.DEFAULT.get("png"); // image/png
Practical example
To find MIME Type when we know file extension we can use MimeMappings class.
import org.springframework.boot.web.server.MimeMappings;
public class Program {
public static void main(String[] args) {
String fileExtension = "png";
String mimeType = MimeMappings.DEFAULT.get(fileExtension);
System.out.println(mimeType); // image/png
}
}