Blob: type property
Value
A string containing the file's MIME type, or an empty string if the type could not be determined.
Examples
This example asks the user to select a number of files, then checks each file to make sure it's one of a given set of image file types.
HTML
html
<input type="file" id="input" multiple />
<output id="output">Choose image files…</output>
JavaScript
js
// Our application only allows GIF, PNG, and JPEG images
const allowedFileTypes = ["image/png", "image/jpeg", "image/gif"];
const input = document.getElementById("input");
const output = document.getElementById("output");
input.addEventListener("change", (event) => {
const files = event.target.files;
if (files.length === 0) {
output.innerText = "Choose image files…";
return;
}
const allAllowed = Array.from(files).every((file) =>
allowedFileTypes.includes(file.type)
);
output.innerText = allAllowed
? "All files clear!"
: "Please choose image files only.";
});
Result
Specifications
Specification |
---|
File API # dfn-type |
Browser compatibility
BCD tables only load in the browser