filestack / filestack-js

Official Javascript SDK for the Filestack API and content ingestion system.
https://www.filestack.com
MIT License
206 stars 79 forks source link

'Accept' parameters on drag / drop #402

Open ryancschulz opened 3 years ago

ryancschulz commented 3 years ago

It appears the file type 'accept' parameters are not being respected when a user drags a file into picker from file browser on local machine. Is there a way to handle this so those files can be rejected when drag and dropped? It works correctly when user selects via picker.

tomgibb commented 3 years ago

Happy to see this - was going a bit mad kicking it around. Of note, params like "maxFiles" work and produce an error message.

m-revetria commented 3 years ago

I'm experiencing the same issue, users can drag and drop files with mime types that are not accepted. I was able to work around it by implementing the onFileSelected callback and throwing an exception when a file's mime type is not supported, the error's message is shown in the filepicker modal

Screenshot from 2020-12-14 15-02-36


var supportedTypes = [
    'image/jpeg',
    'image/png'
];
filestackClient.picker({
  accept: supportedTypes,
  onFileSelected: function(file) {
    if (!supportedTypes.includes(file.mimetype)) {
        throw new Error("Unsupported file type '" + file.mimetype + "'.");
    }
  },
  // Other settings
}).open()