Hello !, I have a component for input file
to load files .cer
and .key
.
The problem I have is that I do not recognize the extension application / x-iwork-keynote-sffkey and the tipo
of the document returns it as a string vacío
.
The code is as follows:
onFileChange(event, idDocument) {
const file = event.target.files[0];
if (!file) {
return;
}
if (this.validFileType === 'cer' && file.type !== 'application/x-x509-ca-cert') {
swal('Formato de archivo inválido', 'Sólo puedes subir archivos .cert', 'error');
return;
} else if (this.validFileType === 'key' && file.type !== 'application/x-iwork-keynote-sffkey') {
swal('Formato de archivo inválido', 'Sólo puedes subir archivos .key', 'error');
return;
}
if (file.size > 15000000) {
swal('Tamaño no permitido', 'Sólo puedes subir archivos con un tamaño máximo de 15MB', 'error');
return;
}
this.filename = file.name;
}
<div class="form-group mt-3 mb-0 display-inline-block">
<input type="file" name="{{ name }}" id="{{ name }}" class="inputfile form-control-file display-hidden" (change)="onFileChange($event, name)" accept=".{{ validFileType }}" />
<a class="{{ style }}" (click)="openFileBrowser($event, name)">
<span class="text-bold-300">{{ inputMessage }}</span>
</a>
{{ filename }}
</div>
However, with the tipo
file .cer
, it does return the type of extension: