File Media Types

Introduction

A media type, sometimes also called Content-Type (due to its use in HTTP standards) or MIME type (due to its use in email standards), is used to classify the content of a message or response in the Internet. The media type is used to decide how to handle the data received from another system (file downloads, email attachments etc.)

But how does FNZ Studio determine media types?

Media types can be compared with file extensions like .pdf or.gif. In fact, most of the time the media type is determined by looking at the file extension.

A media type is composed of at least two parts: a type, a subtype, and one or more optional parameters. The type part is separated from the subtype part by a slash. Some very common media types are:

  • text/plain, text/html or text/xml
  • image/gif, image/png or image/jpeg
  • application/pdf, application/msword or application/octet-stream
  • audio/mp4, video/quicktime or multipart/mixed

If a user downloads a file from a web server, the server usually adds an HTTP header Content-Type to the response. The value of this header is the media type of the file content.

It is very important the media type matches the file extension, and the actual content of the file. Depending on this information, browsers decide what to do with the file. The file may be displayed in the current window, or the browser may pass the file to a plug-in, or display an open/save dialog. Not all browsers use the same logic for this decision. Most of them rely on the media type (if it is present). Others might analyze the content of the file or use the file extension. To get a consistent behavior, it is important that these three elements match.

Media Types in FNZ Studio

If a document is downloaded from within FNZ Studio, FNZ Studio tries to guess the correct media type from the file extension. This media type is then added to the HTTP response header as Content-Type.

The list of file formats, file extensions and media types is almost endless and every day someone specifies a new file format. It is therefore impossible to keep a list of all know file extensions and media types within FNZ Studio.

Therefore determining a media type is a procedure that involves multiple steps.

Configuration File mime-types.properties

FNZ Studio first checks if the file <DataHome>/conf/mime-types.properties exists. If it does, it is expected to contain pairs of file extensions and corresponding media types in the Java Properties file format:

Copy
gif = image/gif
pdf = application/pdf
ppt = application/vnd.ms-powerpoint

If the file extension is found in this file, the specified media type is used as value for the Content-Type HTTP header. If the file doesn't exist or if it doesn't contain the required file extension, FNZ Studio proceeds with steps described in the next section.

Changes to this file are immediately active. There is no need to restart the web application or application server.

Application Server Configuration

If the file extension is not listed in the mime-types.properties file (or if the file doesn't exist), FNZ Studio tries to get a media type from the servlet engine.

Most Java application servers and servlet engines (like Apache Tomcat) allow an administrator to define mappings between file extensions and media types somewhere in their configuration. The Java servlet specification defines an API how a web application may ask the servlet engine for a media type given a file extension.

FNZ Studio uses this API to find a media type. If the servlet engine returns a media type, FNZ Studio uses this value as Content-Type HTTP header.

Hard-Coded Media Types

If neither the configuration file nor the servlet engine can provide a media type for the file extension, FNZ Studio has some built-in mappings:

Copy
gif = image/gif
png = image/png
jpg = image/jpeg
css = text/css
js = text/javascript
txt = text/plain
htm = text/html
html = text/html
xml = text/xml
pdf = application/pdf
doc = application/msword
xls = application/vnd.ms-excel
ppt = application/vnd.ms-powerpoint
awexport = application/x-appway-export
awbackup = application/x-appway-backup

These mappings are hard-coded. You cannot change them. But keep in mind that media types defined in the configuration file mime-types.properties or on the servlet engine level always take precedence over these built-in mappings.

Generic Media Type

Finally, if everything above fails, FNZ Studio uses a generic media type:

Copy
application / octet - stream

Resource Business Objects

Resource Business Objects have a property where a user can specify the media type of the resource content. If this property has been set, its value is used directly. If the property doesn't have a value, the above algorithm is used to determine a media type.