Skip to main content
Question

BOX UI Element File Uploader

  • May 22, 2025
  • 3 replies
  • 49 views

Forum|alt.badge.img

Hi, 

How to validate file format before uploading file using BOX UI Element -Box Content Uploader?

 

Ref : https://developer.box.com/docs/box-content-uploader 


Regards, 

VinayV

3 replies

Forum|alt.badge.img

Hi VinayV,

 

You could listen for the upload complete event (docs here), which will return an array of file objects (docs here). That should have enough information for you to validate the content that was uploaded.

 

Thanks,

Jon


Forum|alt.badge.img

Hi jcleblanc,

             But i want to validate the file type before upload complete. i have added a listener 'beforeupload' where i could retrieve the added files before upload, but i was not able to cancel the event in case of invalid file type. Check the code as below.

uploader.on('beforeupload', (data) => {
if (data != undefined) {
var fileName = data[0].name;
var ext = (-1 !== fileName.indexOf('.')) ? fileName.replace(/.*[.]/, '').toLowerCase() : '';
var allowed = ['doc', 'docx', 'xls', 'xlsx', 'pdf'];

if (!allowed.length) { return true; }

for (var i = 0; i < allowed.length; i++) {
if (allowed[i].toLowerCase() == ext) { return true; }
}

alert('This file types are not allowed to upload!');
return false;
}

});

 

It would be great if you could help me resolve this issue.


Forum|alt.badge.img

Hi Ranjith!

Were you able to resolve this issue? I'm trying to implement the same functionality.

Thanks,

Gerard