52
Views
6
Comments
Solved
File size validation is working only for 1st row in a List
Question
Application Type
Reactive

Hi All,

I am working on a scenario, where i need to set the file limit to 5MB to upload list of files at one time.

for this I am using javascript to get filesize and performing validation, but it is working for only first row and for the rest of the rows it is failing. I think the javaScript i am using here has an issue, can anyone please tell me the error in javascript I am using.


I am attaching sample Poc for this issue.

URL: Demo Screen

can someone help me here.

Thank You,

Rahul.

FileSizePoc.oml
UserImage.jpg
Rakhi Chouhan
Solution

Hi Rahul,
You can check these discussion related file upload . May it will help you to get the proper solution.

UserImage.jpg
Kumar S

Hi,

Thank You, it worked..

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Sorry Rahul,

i read a bit too quick through your post, your start isn't right, it should be querySelectorAll instead of querySelector.  And the files[0] was correct, sorry for saying it wasn't. 

See attached your oml with modifications.  What i changed : 

  • added a totalsize running total
  • changed querySelector to querySelectorAll
  • added a for loop to go through all upload objects
  • add all file sizes to the running total

Dorine

FileSizePocEdited.oml
2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi Rahul,

Your start is good, querySelector produces a list of elements.

But you don't have any logic for looping through the list, you are only looking at the first one : [0].

Also, what exactly is your requirement, that no single file goes over 5MB, or the total size of all files together.  

So loop the elements, in first case set filesize to the largest one you find, in second case set it to the sum.

Either way, I would probably have a boolean as result, and have a max size as input variable.

Dorine

UserImage.jpg
Kumar S

Hi,

Thank You for the response,

I am looking for the first case you mentioned, can you please brief your solution.

Sry, I did not get exact solution u mentioned.


Thank you. 

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Sorry Rahul,

i read a bit too quick through your post, your start isn't right, it should be querySelectorAll instead of querySelector.  And the files[0] was correct, sorry for saying it wasn't. 

See attached your oml with modifications.  What i changed : 

  • added a totalsize running total
  • changed querySelector to querySelectorAll
  • added a for loop to go through all upload objects
  • add all file sizes to the running total

Dorine

FileSizePocEdited.oml
UserImage.jpg
Rakhi Chouhan
Solution

Hi Rahul,
You can check these discussion related file upload . May it will help you to get the proper solution.

UserImage.jpg
Kumar S

Hi,

Thank You, it worked..

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