Я заставил это работать так:
public dropped(event: UploadEvent) {
if (event.files.length > 1) {
alert("impossible de rajouter plus d'un document à la fois");
} else {
this.verifierEnvoyerDocument(event.files[0]);
}
}
verifierEnvoyerDocument(droppedFile: UploadFile) {
this.file = droppedFile;
// Is it a file and is it allowed?
if (droppedFile.fileEntry.isFile && this.isFileAllowed(droppedFile.fileEntry.name)) {
const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
fileEntry.file((file: File) => {
console.log('isFile :', file.name);
console.log(droppedFile.relativePath, file);
this.envoyerDocument(droppedFile.relativePath, file);
});
} else {
alert("Seul les fichiers au format '.doc', '.docx', '.ppt', '.pptx', '.pdf' sont accepté.");
}
}
isFileAllowed(fileName: string) {
let isFileAllowed = false;
const allowedFiles = ['.doc', '.docx', '.ppt', '.pptx', '.pdf'];
const regex = /(?:\.([^.]+))?$/;
const extension = regex.exec(fileName);
if (isDevMode()) {
console.log('extension du fichier : ', extension);
}
if (undefined !== extension && null !== extension) {
for (const ext of allowedFiles) {
if (ext === extension[0]) {
isFileAllowed = true;
}
}
}
return isFileAllowed;
}
Надеюсь, это кому-нибудь поможет.