pattern-library icon indicating copy to clipboard operation
pattern-library copied to clipboard

FileUpload total file size calculation

Open martinoss opened this issue 2 years ago • 0 comments

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

  1. 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
  2. Add sample file (exactly 500KB) 500kb.pdf
  3. Notice the error regarding the exceeded total file size for all files
  4. 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

martinoss avatar Jan 25 '23 16:01 martinoss