You are viewing limited content. For full access, please sign in.

Question

Question

Odd Forms File Upload Question. Maybe someone with web dev experience can answer

asked on June 19, 2023 Show version history

Wondering why, after uploading a file to an upload field and checking the properties, the FileList remains empty.

Reason being that I would like to do some verifications of the file contents in real time before proceeding, but I can not access it when the list is empty.

The way I access files from an input object of type file is

input.files[#]

But with an empty list, this will always be null

0 0

Answer

SELECTED ANSWER
replied on June 19, 2023

Forms doesn't really store upload files in the input element on the form. The input element is used, but the file is actually uploaded to Forms with a reference guid.

This is a fairly common practice and is helpful for various reasons, like reducing the amount of data required to submit/post the form, or validating/scanning uploaded files prior to submission.

I assume you're using the classic designer since you want to access DOM elements, but if this is in a different version, things are probably quite different.

 

If you inspect the clickable file name after uploading a file, you'll see a reference URL with the file guid and that is contained in a "files" table which in the same container as the input.

One thing you can do is use the "files" table to get a file count based on the number of child tr elements within the table that have the "file" class.

Here's an example that counts the number of attachments for every "files" table on a form or for a specific upload field.

$('.files').each(function(){
  console.log($(this).find('.file').length);
});

console.log($('.myFileUpload .files .file').length);
2 0
replied on June 20, 2023

Ah I figured it might be tucked away somewhere else. I am using the classic designer but my HTML looks a bit different than yours, maybe because it is in LF Cloud.

With a custom input, not only can I count the number of attachments but I can read them too. Is it not possible to read the contents of a file uploaded to a native upload field?

Thanks for the explanation!

0 0
replied on June 20, 2023

There's no way that I'm aware of since the upload field is really more like an interface for storing files server side.

I think they made some changes to how file uploads were handled that affected newer forms, so I'm not sure if the blob url is still available somewhere. If you can find it then maybe you can use that to read the file data.

The screenshot I shared is from an older form, but when I test it out on newly-created file uploads I don't see the url either.

0 0
replied on June 20, 2023

Ok that works. I might be able to just use a custom HTML input field for this specific process since we only need the data from the file for the rest of the process and it can be copied to official table fields.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.