8
Views
2
Comments
Solved
[Binary Data Client Actions] Can't get the file size to work, and doesn't seem to work in the demo?
Forge component by Nikhil Gaur
3
Published on 11 Dec 2020
Application Type
Reactive

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?

mvp_badge
MVP
Rank: #75
Solution

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

Rank: #2002

Works like a dream, thanks!