pattern-library
pattern-library copied to clipboard
FileUpload total file size calculation
I just noticed that the total file size calculation possibly has a bug.
It seems that when adding a single file, it will be counted twice for the total size over all files.
How to reproduce
- Go to this storybook page: https://axa-ch-webhub-cloud.github.io/plib-feature/develop/?path=/story/components-file-upload--file-upload&args=maxSizeOfSingleFileKB:500;maxSizeOfAllFilesKB:999 Notice that max single file size is capped at 500KB and max size of all files is 999KB
- Add sample file (exactly 500KB) 500kb.pdf
- Notice the error regarding the exceeded total file size for all files
- Increase the limit from 999 to 1000, then it works.
A first look into the source suggests that these two lines probably needs to be flipped.
https://github.com/axa-ch-webhub-cloud/pattern-library/blob/eca9f02be6af012e649036d337cf1034afe8fc48/src/components/20-molecules/file-upload/index.js#L442-L443
On line 406, sizeOfAllFilesInBytes
already has the value of 512000 when previewing the future total including the new file to be added.
https://github.com/axa-ch-webhub-cloud/pattern-library/blob/eca9f02be6af012e649036d337cf1034afe8fc48/src/components/20-molecules/file-upload/index.js#L398-L413