0

I'm trying to understand how the Uppy library implements the feature of preventing certain files from being selected in the system's file picker using the concept of Restrictions. When accessing the Uppy examples page, I noticed that if I check the "Restrictions" checkbox and click on "Browse files," all files available in the user's storage are listed, but those that do not meet the format and size restrictions are disabled for selection.

enter image description here

I understand that it is possible to bypass Uppy's restrictions by choosing "All files" instead of "Custom files" in the system's file dialog. However, I'm specifically looking for strategies to restrict files during the file picking process, in addition to the format, using browser APIs.

I also understand that limiting which files can be selected for upload on the client-side is not a specific feature of Uppy, as it is possible to restrict the allowed file types using the accept attribute of the input tag. However, I would like to add more restrictions to the files that the user can select in the file picker, for example per type file size limit and total files size limit. It seems that this kind of customization goes beyond the scope of the input element.

I'm aware of how to prevent the user from uploading files that do not meet the upload rules, by presenting an error message if the file is not suitable. However, what I'm interested in is a way to interact with the system's file manager to prevent the user from selecting these files in the first place.

Can anyone provide insights into how Uppy achieves this file selection restriction feature, pointing out code from its Github repository? I'm looking for details on the underlying implementation and how Uppy interacts with the browser's APIs to achieve this behavior.

Alternatively, answers on how to achieve the same effect, even without reference to the Uppy library, will be accepted.

Related questions:

Kfcaio
  • 442
  • 1
  • 8
  • 20
  • 1
    HTML `file` input elements have an [`accept`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept) attribute which can limit the file types. This is not an Uppy-specific feature. – Rory McCrossan Jul 25 '23 at 11:08
  • I have edited the question to make it clearer that the type of restriction I am looking to implement goes beyond the scope of the input tag. Please check the third paragraph above. – Kfcaio Jul 25 '23 at 11:23
  • It's not possible to restrict the local file picker to display files limited by size. That validation would need to be done in your business logic after file selections have been made. For details on how to do that, see the new duplicate I added. – Rory McCrossan Jul 25 '23 at 11:40
  • Did you manage to test the Uppy playground? That very restriction was implemented there. That's what I would like to understand at the browser API level. Therefore, I believe my question is not a duplicate and could help others with the same doubt. – Kfcaio Jul 25 '23 at 14:30

0 Answers0