La propiedad type
de un objeto Blob
proporciona el tipo MIME del archivo. Retorna una cadena vacía si el tipo no puede ser determinado.
Sintaxis
var tipo = instanceOfFile.type
Valor
Una cadena
Ejemplo
var i, fileInput, files, allowedFileTypes;
// fileInput es un HTMLInputElement: <input type="file" multiple id="myfileinput">
fileInput = document.getElementById("myfileinput");
// files es un objeto FileList (similar a NodeList)
files = fileInput.files;
// nuestra aplicacion solo acepta imagenes *.png, *.jpeg y *.gif
allowedFileTypes = ["image/png", "image/jpeg", "image/gif"];
for (i = 0; i < files.length; i++) {
// Prueba si file.type es un tipo de archivo permitido.
if (allowedFileTypes.indexOf(files[i].type) > -1) {
// El tipo de archivo es uno de los permitidos. Hacer algo aquí.
}
});
Especificaciones
Espeficicaciones | Estado | Comentario |
---|---|---|
File API La definición de 'type' en esta especificación. |
Working Draft | Definicion inicial. |
Compatibilidad con browsers
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
File.type | 5 | (Yes) | 4.0 (2) | 10.0 | 11.10 | 5.1 |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
File.type | Sin soporte | (Yes) | Sin soporte | Sin soporte | Sin soporte | Sin soporte |