Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUpload total file size calculation #2404

Open
martinoss opened this issue Jan 25, 2023 · 0 comments
Open

FileUpload total file size calculation #2404

martinoss opened this issue Jan 25, 2023 · 0 comments

Comments

@martinoss
Copy link

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.

this.sizeOfAllFilesInBytes += fileSize;
this.validateOverallSize(fileSize);

On line 406, sizeOfAllFilesInBytes already has the value of 512000 when previewing the future total including the new file to be added.

validateOverallSize(fileSize = 0) {
const {
sizeOfAllFilesInBytes,
maxSizeOfAllFilesKB,
filesTooBigStatusText,
} = this;
const maxSizeOfAllFilesInBytes = getBytesFromKilobyte(maxSizeOfAllFilesKB);
if (sizeOfAllFilesInBytes + fileSize > maxSizeOfAllFilesInBytes) {
this.globalErrorMessage = filesTooBigStatusText;
this.invalid = true;
} else {
this.globalErrorMessage = '';
this.invalid = false;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant