Skip to main content
Question

Restricting file type in Box Content Uploader

  • May 22, 2025
  • 5 replies
  • 173 views

Forum|alt.badge.img

Hello,

Is there a way to restrict the file types allowed to be uploaded through the Box Content Uploader (React UI element)? I could only find the following posts about it and it doesnt seem like there is support for handling file restrictions:
https://support.box.com/hc/en-us/community/posts/360049138574-File-restriction-based-on-extensions
https://support.box.com/hc/en-us/community/posts/360052614673-Box-UI-Elements-Content-Uploader?input_string=Restricting%20file%20type%20in%20Box%20Content%20Uploader
https://github.com/box/box-ui-elements/issues/489


The first link is not very helpful as the linked article is about error codes. The second link, the user reports that there isn't a way to stop the upload event from happening based on the file types they're looking for. The third link they closed the issue out without stating any intention of implementing this feature into the content uploader

5 replies

Forum|alt.badge.img

Hello! 

The best approaches are to:

  • add the requestIntercepter to throw an error if a user tires to upload any file types you do not want to allow
  • using the accept attribute on the input file field

Hope this helps! 

Best,

Kourtney, Box Developer Advocate


Forum|alt.badge.img

Hi Kourtney,

Thanks for the response! How would you go about using the accept attribute on the input file field? I don't see the Content Uploader accepting any properties related to extensions or an <input> element being used in the code.


Forum|alt.badge.img

I've implemented the requestInterceptor to throw an error, but the ContentUploader continues to retry uploading the files. Is there a way to stop the upload based on the thrown error?


Forum|alt.badge.img

For anyone who needs to restrict file extensions in the future, our solution was to parse the file extension from the filename located in config.data.name and if it was not one of our accepted extensions, we would null out the folder id the file is getting uploaded to (config.data.parent.id = null). There was a very tricky error with this though. Since the file upload to Box is chunked, the config object does not always contain the filename. So you must wrap your parsing of the extension in an if statement to check if the filename is present: if (!!config?.data?.name). If you don't do this, the upload will keep trying until it fails and nothing about this error will be logged to the console.


Forum|alt.badge.img

Hello DPL Admin,

I use API BOX in my project , and i want to upload only the file with the type "PDF",

but i don't know how to do it.

Is there a way to restrict the file types allowed to be uploaded ?