filepond icon indicating copy to clipboard operation
filepond copied to clipboard

[Bug] text/markdown custom file validation not working

Open YaroBear opened this issue 9 months ago • 1 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Have you updated FilePond and its plugins?

  • [x] I have updated FilePond and its plugins

Describe the bug

I want to restrict file uploads to only Markdown (.md) files. However, since most browsers do not reliably detect the MIME type for .md files, I understand that a custom fileValidateTypeDetectType function is required. The custom validation function provided does not work as expected.

Reproduction

  • Set the acceptedFileTypes property to ".md" which limits the file picker to only select files with the .md extension
  • Resolve "text/markdown" or "text/plain" for the fileValidateTypeDetectType
  • Get "File is of invalid type" error message

See this codesandbox: https://codesandbox.io/p/devbox/friendly-butterfly-pxqm92?workspaceId=ws_PrPLhqSkCsZkRf6v6g8FR1

Environment

- Device: Macbook Pro M3
- OS: MacOS 15.3.1
- Browser: Firefox Developer Edition, Edge, and Safari

YaroBear avatar Feb 25 '25 00:02 YaroBear

Hi,

The acceptedFileTypes requires a mime type, not an extension. https://pqina.nl/filepond/docs/api/plugins/file-validate-type/#properties

In this case you can set ['text/markdown'], then in the fileValidateTypeDetectType you return 'text/markdown' when the extension is '.md'

rikschennink avatar Mar 17 '25 08:03 rikschennink