Blob.type
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
La propriété type
de l'objet Blob
fourni le type MIME (Internet media type) d'un fichier. Celle-ci retourne une chaîne de caractère vide si le type n'a pas pu être déterminé.
Syntaxe
js
var mimetype = instanceOfFile.type;
Valeur
Une chaîne de caractères (par exemple : "image/png").
Exemple
js
var i, fileInput, files, allowedFileTypes;
// fileInput est un HTMLInputElement: <input type="file" multiple id="myfileinput">
fileInput = document.getElementById("myfileinput");
// files est un objet FileList (similaire à NodeList)
files = fileInput.files;
// notre application accepte seulement les images de type *.png, *.jpeg et *.gif
allowedFileTypes = ["image/png", "image/jpeg", "image/gif"];
for (i = 0; i < files.length; i++) {
// Vérifie si file.type est un type autorisé.
if (allowedFileTypes.indexOf(files[i].type) > -1) {
// le type du fichier (file) correspond à l'un des types autorisés. Faites quelque chose ici.
}
});
Spécifications
Specification |
---|
File API # dfn-type |
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.