[Binary Data Client Actions] Can't get the file size to work, and doesn't seem to work in the demo?
Reactive icon
Forge component by Nikhil Gaur
Application Type

In the "Try Now" and when I tried implementing, I could not get the file type to be anything other than 'file' - and file.length seems undefined so the file size is always 0.  Any ideas?


Hi Andy,

I have checked the respective Forge component's client action i.e. GetFileCotentType and observed a small JS mistake which is causing this problem.

Change 1:

  • I have replaced the document.querySelectorAll() with document.querySelector()

Change 2:

  • The FileList object does have properties like name, size and the contents of the files.
  • In the actual implementation the upload widget/file type input object is not referring the files property (object type) and thus the files object - length property value is undefined.
  • Syntax: fileuploadObject.files

Working JavaScript Snippet:

if (window.FileReader && window.Blob) {
    var uploadControl = document.querySelector('#' + $parameters.UploadId + ' > input[type="file"]');
    var files = uploadControl.files; // this was missing
    var contentTypes = [];
    for(var i = 0; i < files.length; i++) {
        contentTypes[i] = files[i].type;
    $parameters.ContentTypes = JSON.stringify(contentTypes);

Hope this helps you!

Kind regards,

Benjith Sam

Works like a dream, thanks!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.