![](/uploads/1/2/7/6/127609584/270469667.jpg)
Important: Browsers use the MIME type, not the file extension, to determine how to process a URL, so it's important that web servers send the correct MIME type in the response's header. If this is not correctly configured, browsers are likely to misinterpret the contents of files and sites will not work correctly, and downloaded files may be mishandled. Structure of a MIME typeThe simplest MIME type consists of a type and a subtype; these are each strings which, when concatenated with a slash ( /) between them, comprise a MIME type.
![Javascript Javascript](http://www.cuplayer.com/player/uploads/allimg/120528/1149215Y7-1.jpg)
No whitespace is allowed in a MIME type: type/ subtypeThe type represents the general category into which the data type falls, such as video or text. The subtype identifies the exact kind of data of the specified type the MIME type represents. For example, for the MIME type text, the subtype might be plain (plain text), html ( source code), or calendar (for iCalendar/.ics) files.Each type has its own set of possible subtypes, and a MIME type always has both a type and a subtype, never just one or the other.An optional parameter can be added to provide additional details: type/ subtype; parameter= valueFor example, for any MIME type whose main type is text, the optional charset parameter can be used to specify the character set used for the characters in the data. If no charset is specified, the default is ( US-ASCII) unless overridden by the settings. To specify a UTF-8 text file, the MIME type text/plain;charset=UTF-8 is used.MIME types are case-insensitive but are traditionally written in lowercase, with the exception of parameter values, whose case may or may not have specific meaning. TypesThere are two classes of type: discrete and multipart. Discrete types are types which represent a single file or medium, such as a single text or music file, or a single video.
A multipart type is one which represents a document that's comprised of multiple component parts, each of which may have its own individual MIME type; or, a multipart type may encapsulate multiple files being sent together in one transaction. For example, multipart MIME types are used when attaching multiple files to an email.
Saving binary data as file using JavaScript from a browser. Ask Question Asked 5 years, 11 months ago. Active 8 months ago. Viewed 112k times 47. I am working on a business application using angularJS. One of my service method returning me a byte (inclding PDF.
Discrete typesThe discrete types currently registered with the IANA are: application Any kind of binary data that doesn't fall explicitly into one of the other types; either data that will be executed or interpreted in some way or binary data that requires a specific application or category of application to use. Generic binary data (or binary data whose true type is unknown) is application/octet-stream. Other common examples include application/pdf, application/pkcs8, and application/zip. Audio Audio or music data. Examples include audio/mpeg, audio/vorbis. Example Reserved for use as a placeholder in examples showing how to use MIME types. These should never be used outside of sample code listings and documentation.
Example can also be used as a subtype; for instance, in an example related to working with audio on the web, the MIME type audio/example can be used to indicate that the type is a placeholder and should be replaced with an appropriate one when using the code in the real world. Font Font/typeface data. Common examples include font/woff, font/ttf, and font/otf. Image Image or graphical data including both bitmap and vector still images as well as animated versions of still image formats such as animated or APNG. Common examples are image/jpeg, image/png, and image/svg+xml.
Model Model data for a 3D object or scene. Examples include model/3mf and model/vml. Text Text-only data including any human-readable content, source code, or textual data such as comma-separated value (CSV) formatted data. Examples include text/plain, text/csv, and text/html. Video Video data or files, such as MP4 movies ( video/mp4).For text documents without a specific subtype, text/plain should be used. Similarly, for binary documents without a specific or known subtype, application/octet-stream should be used.
Multipart typesMultipart types indicate a category of document broken into pieces, often with different MIME types; they can also be used — especially in email scenarios — to represent multiple, separate files which are all part of the same transaction. They represent a composite document.With the exception of multipart/form-data, used in the method of, and multipart/byteranges, used with Partial Content to send part of a document, HTTP doesn't handle multipart documents in a special way: the message is transmitted to the browser (which will likely show a 'Save As' window if it doesn't know how to display the document).There are two multipart types: message A message that encapsulates other messages. This can be used, for instance, to represent an email that includes a forwarded message as part of its data, or to allow sending very large messages in chunks as if it were multiple messages. Examples include message/rfc822 (for forwarded or replied-to message quoting) and message/partial to allow breaking a large message into smaller ones automatically to be reassembled by the recipient.
Multipart Data that is comprised of multiple components which may individually have different MIME types. Examples include multipart/form-data (for data produced using the API) and multipart/byteranges (defined in and used with 's 'Partial Content' response returned when the fetched data is only part of the content, such as is delivered using the header). Important MIME types for Web developers application/octet-streamThis is the default for binary files. As it means unknown binary file, browsers usually don't execute it, or even ask if it should be executed. They treat it as if the header was set to attachment, and propose a 'Save As' dialog.
Text/plainThis is the default for textual files. Even if it really means 'unknown textual file,' browsers assume they can display it. Note that text/plain does not mean 'any kind of textual data.' If they expect a specific kind of textual data, they will likely not consider it a match. Specifically if they download a text/plain file from a element declaring a CSS file, they will not recognize it as a valid CSS file if presented with text/plain. The CSS mime type text/css must be used. Text/cssCSS files used to style a Web page must be sent with text/css.
If a server doesn't recognize the.css suffix for CSS files, it may send them with text/plain or application/octet-stream MIME types. If so, they won't be recognized as CSS by most browsers and will be ignored. Text/htmlAll HTML content should be served with this type. Alternative MIME types for XHTML (like application/xhtml+xml) are mostly useless nowadays. Note: Use application/xml or application/xhtml+xml if you want XML’s strict parsing rules, sections, or elements that aren't from HTML/SVG/MathML namespaces. Text/javascriptPer the HTML specification, JavaScript files should always be served using the MIME type text/javascript. Note: Even though any given may support any or all of these, you should only use text/javascript.
It's the only MIME type guaranteed to work now and into the future.Some content you find may have a charset parameter at the end of the text/javascript media type, to specify the character set used to represent the code's content. This is not valid, and in most cases will result in a script not being loaded. Image typesFiles whose MIME type is image contain image data. The subtype specifies which specific image file format the data represents.
Guides:. Resources and URIs.
HTTP guide. HTTP security. References:. HTTP headers. HTTP request methods. HTTP response status codes. CSP directives.
CORS errors. Feature-Policy directives.
Adding Static Content MIME Mappings. 3 minutes to read.In this articleOverviewThe element of the element adds a unique MIME type to the collection of static content types. Each entry must consist of two parts:. A unique file name extension that is specified by the fileExtension attribute, for example, '.txt', '.png', etc. A MIME type for the file name extension that is specified by the mimeType attribute, for example, 'text/plain', 'image/jpg', etc.
![](/uploads/1/2/7/6/127609584/270469667.jpg)