MDN wants to talk to developers like you: https://qsurvey.mozilla.com/s3/8d22564490d8

File.type

Summary

The type property provides the MIME type of the file or null if the type couldn't determined.

Syntax

var mimetype = instanceOfFile.type

Value

A string or null

Example

// fileInput is a HTMLInputElement: <input type="file" multiple id="myfileinput">
var fileInput = document.getElementById("myfileinput");

// files is a FileList object (simliar to NodeList)
var files = fileInput.files;

// our application only allows *.png, *.jpeg and *.gif images
var allowedFileTypes = ["image/png", "image/jpeg", "image/gif"];

for (var i = 0; i < files.length; i++) {
  // if selected file type is contained in allowFileTypes
  if (allowedFileTypes.indexOf(files[i].type) > -1) {
    // do something
  }
}

Specifications

Specification Status Comment
File API Working Draft Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
File.name 5 Unknown (4) 10.0 11.10 5.1
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
File.name Not supported Not supported Not supported Not supported Not supported

See also

Document Tags and Contributors

 Last updated by: Jeremie,