filepond-plugin-file-validate-type
filepond-plugin-file-validate-type copied to clipboard
File type validation behaves differently when dropping a folder
I set up file type validation with the folloing accepted types:
acceptedFileTypes: [ 'image/', 'audio/', 'video/', 'text/', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/application/vnd.openxmlformats-officedocument.presentationml.slideshow', 'application/x-zip-compressed', ],
When dropping files directly (not dropping a folder) it works perfectly (see attached image validateType_directly.png). When dropping a folder containing the exactly same files as before, some (but not all) files types are blocked (see attached image validateType_folder.png), although they should be accepted.
So it seems, files are processed differently when a folder ist dropped.
Any advice is highly appreciated.
PS: After deactivation of FilePondPluginFileValidateType, upload works correctly, no matter if the files are contained in a folder or not (of course all files are accepted in this case).

You can can try to see how the browser interprets the files using the fileValidateTypeDetectType hook, maybe there's a difference and you can use the hook to correct the browser interpretation. https://pqina.nl/filepond/docs/patterns/plugins/file-validate-type/#custom-type-detection
Thanks for your response. I used fileValidateTypeDetectType to determine the types of the files added. When adding one image and one DOCX-Document directly, the files are recognized as "object file" and the types are shown correctly (see first image below).
But when adding the same files by adding the containing directory, the files are recognized as "object blob" and the type of the DOCX-blob is empty, whereas the file type of the image-blob ist still shown correctly (see second image below). Is there a (simple) way to obtain the types of the blobs not recognized?

I'll see if I have some time to investigate this next week.
Thanks in advance!
@alex7654 Just checked. The browser doesn't recognise the file type when read from a folder vs when a file is dropped on its own (don't know why).
When dropping a folder FilePond tries to guesstimate the file extension and creates a Blob instead of a File because it can't create File objects on IE11. I'm pushing a fix (4.23.1) where it doesn't create a Blob if the type cannot be guesstimated. But still that means the type is empty and you will have to correct for it in the fileValidateTypeDetectType method. I'd advise to do so by checking the extension and mapping it to one of the mime types in the accepted file types list.
Thank you for the update!