joi, 16 aprilie 2015

[OmniFaces utilities (2.0)] Check the mime type for the given file name


[OmniFaces utilities] The getMimeType() method returns the mime type for the given file name. The mime type is determined based on file extension and configureable by <mime-mapping> entries in web.xml. When the mime type is unknown, then a default of application/octet-stream will be returned.

Method:
See also: Faces#getContext()
Usage:

import org.omnifaces.util.Faces;
...
// e.g. image/png
String mimetype = Faces.getMimeType("rafa.png");

You may need the mime type of a file at download, in order to set the content type, as below:

response.setContentType(mimetype);

Niciun comentariu:

Trimiteți un comentariu