Languages
[Edit]
EN

Spring Boot 2 - get MIME Type by file extension

7 points
Created by:
Efe-V
409

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
    }
}

 

See also

  1. Java - get file extension

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join