-
Notifications
You must be signed in to change notification settings - Fork 72
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
base: release-v1.6.0
Are you sure you want to change the base?
fix(upload): Fix total documents size limit calculation #7843
Conversation
const resizedImage = | ||
Boolean(options.maxSizeMB) && | ||
bytesToMB(uploadedImage.size) > options.maxSizeMB && | ||
(await imageCompression(uploadedImage, options)) | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
return { | ||
fileAsBase64: fileAsBase64.toString(), | ||
resized | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
This is a fix for the issue #7840 : Incorrect File Size Calculation During Upload for Compressed Files in Birth Registration