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

fix(upload): Fix total documents size limit calculation #7843

Open
wants to merge 2 commits into
base: release-v1.6.0
Choose a base branch
from

Conversation

nifaliana
Copy link

This is a fix for the issue #7840 : Incorrect File Size Calculation During Upload for Compressed Files in Birth Registration

Comment on lines 225 to 229
const resizedImage =
Boolean(options.maxSizeMB) &&
bytesToMB(uploadedImage.size) > options.maxSizeMB &&
(await imageCompression(uploadedImage, options))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! @nifaliana 🙏🏼
I think your approach is correct, I wonder if there is any alternative other than compressing image second time to obtain the file size. One way could be utilizing the output of the processImage function with a small refactor. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tahmidrahman-dsi ,
Thanks for the suggestion 💡 .
I’ve made some improvements and refactored the code as requested.
Let me know if there’s anything else!

Comment on lines +163 to +166
return {
fileAsBase64: fileAsBase64.toString(),
resized
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this so it either returns the blob or the base64'd file. Blob is better if it works as there's not as much overhead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rikukissa ,
Since the function is only used in one place for now and both formats are needed here:

 const newDocument: IFileValue = {
      optionValues,
      type: resizedImage.type || uploadedImage.type,
      data: fileAsBase64.toString(),
      fileSize: resizedImage.size || uploadedImage.size
    }

I think we can keep both OR I suggest adding an optional withCompressed parameter to the processImage function.
This way, we can return:
return withCompressed ? { fileAsBase64: fileAsBase64.toString(), resized } : fileAsBase64.toString();
What do you think?

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

Successfully merging this pull request may close these issues.

3 participants