fix: Banner uploader fix error handling and reduce image size jump#21903
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
| const mutation = trpc.viewer.organizations.update.useMutation({ | ||
| onError: (err) => { | ||
| // Handle JSON parsing errors from body size limit exceeded | ||
| if (err.message.includes("Unexpected token") && err.message.includes("Body excee")) { |
There was a problem hiding this comment.
The unhandled error is: "Unexpected token 'B', "Body excee"... is not valid JSON"
So this takes care of that.
| return canvas.toDataURL("image/png"); | ||
| // Use original format with quality setting for JPEG | ||
| return canvas.toDataURL(originalFormat, originalFormat === "image/jpeg" ? 0.6 : undefined); |
There was a problem hiding this comment.
We don't force convert to png, which was the primary cause for the crazy size jump.
There was a problem hiding this comment.
cubic found 1 issue across 5 files. Review it in cubic.dev
React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.
|
I may be wrong here, but doesn't this limit the image size to just 1mb? |
No, that part never changed. We've always had that limit, but here's what is happening behind the scenes:
|
Does this mean I can upload a 4.5mb PNG file without any issue? Does it get converted to JPEG? |
PNG will not be converted into JPEG. But it would still be compressed enough when cropping. So it would be worth a try 😅 |
E2E results are ready! |
…alcom#21903) * improve uploader * better error handling * unnecessary check * more adjustments * remove logs
What does this PR do?
Adds support for JPEG images in base64 conversion, leading to better adjusted images. Earlier we were forcing base64 png even on jpeg uploads where it would result in a jump of even 30 times in size, in complex images.
Visual Demo (For contributors especially)
A visual demonstration is strongly recommended, for both the original and new change (video / image - any one).
Video Demo (if applicable):
Image Demo (if applicable):
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Checklist
Summary by cubic
Improved the banner image uploader to support JPEG images, reduce large file size jumps, and show clearer error messages when uploads fail.