-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support extensions in acceptedFileTypes #13
Comments
Main Users can now upload spatial files to a NoW Other Fixes an issue where TUSD wouldn't return proper "file type" metadata for obscure file types, such as spatial files Tidies some code Screenshots image Notes It's not possible to nicely display all accepted file extensions for files that share the same MIME type (in our case, "application/octet-stream"--many of these files have no MIME type). pqina/filepond-plugin-file-validate-type#13
Had a problem with
ATE, the file is not recognized by Example with <input type="file" accept="text/plain,image/vnd.dwg"> So I've found a work around to allow file extension with filepond with the current version Filepond optionacceptedFileTypesIn
Example with:
[
"text/plain",
"image/vnd.dwg",
"allowed/extension",
".dwg",
] With that configuration, we are able to see the file by default when browsing the file to upload. fileValidateTypeDetectTypeWe now need to add a custom function to allow extensions.
if (type) {
// Recognized mime type
if (acceptedFileTypes.find(fileType => fileType === type)) {
// Accepted mime type
resolve(type);
} else {
// Rejected mime type
reject(type);
}
} else {
// Unrecognized mime type, looking for a file extension
const uploadedFileExtension = source.name.split('.').pop();
// Checking if the file extension is accepted
const isAllowed = acceptedFileTypes.find(fileType => fileType.split('.').pop() === uploadedFileExtension) !== undefined;
if (isAllowed) {
// Resolve with our "false" mime type
resolve('allowed/extension');
} else {
// Even the extension is not accepted, reject
reject('.' + uploadedFileExtension);
}
} TLDRconst acceptedFileTypes = [
"text/plain",
"image/vnd.dwg",
"allowed/extension",
".dwg",
];
const filepondContainer = document.querySelector('#filepond_container');
this.pond = FilePond.create(filepondContainer, {
// ...
// ...
// ...
// YOUR filepond configuration
// ...
// ...
// ...
allowFileTypeValidation: true,
acceptedFileTypes: acceptedFileTypes,
fileValidateTypeDetectType: (source, type) => new Promise((resolve, reject) => {
if (type) {
// Recognized mime type
if (acceptedFileTypes.find(fileType => fileType === type)) {
// Accepted mime type
resolve(type);
} else {
// Rejected mime type
reject(type);
}
} else {
// Unrecognized mime type, looking for a file extension
const uploadedFileExtension = source.name.split('.').pop();
// Checking if the file extension is accepted
const isAllowed = acceptedFileTypes.find(fileType => fileType.split('.').pop() === uploadedFileExtension) !== undefined;
if (isAllowed) {
// Resolve with our "false" mime type
resolve('allowed/extension');
} else {
// Even the extension is not accepted, reject
reject('.' + uploadedFileExtension);
}
}
}),
}); |
+1 Allowing extensions would also make for a better user experience. Normal users don't know MIME types, but do know file extensions. So the error message above that lists extensions is much more user-friendly than This issue has been open for years without any activity. Is this plugin still supported? When might this issue be addressed? |
I implemented this in a Vue wrapper for FilePond called 'faim': https://github.com/cloydlau/faim#faupload |
The
acceptedFileTypes
option is comparable to the DOMaccept
attribute (it is even populated from the attribute in a progressive-enhancement configuration), so I find myself wanting to use it as a drop-in replacement.If
acceptedFileTypes
contains a file extension,.blah
, it is passed on toaccept
so that the file chooser narrows the selection to.blah
files as desired (in most browsers), but the plugin does not validate.blah
files.While
fileValidateTypeDetectType
can be used to cause.blah
files to be validated, it is an onerous way to configure a behaviour that would work withaccept
: a MIME type and an extension needs to be included inacceptedFileTypes
and the detection function needs to be written.The text was updated successfully, but these errors were encountered: