fix: scale down and compress large AI edit images to WebP to prevent 413 payload too large errors
Build and Deploy / build-and-push (push) Successful in 2m24s

This commit is contained in:
AI Bot
2026-10-05 15:14:21 +05:30
parent 8eb2f844e5
commit f44a07b1a9
2 changed files with 38 additions and 5 deletions
+26 -1
View File
@@ -96,7 +96,32 @@ export const ImageTo3DModal: React.FC<ImageTo3DModalProps> = ({ isOpen, onClose,
setCleanedImageFile(null);
setCleanedImagePreview(null);
try {
const base64 = await fileToDataUrl(fileToClean);
const base64 = await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => {
const img = new Image();
img.onload = () => {
const canvas = document.createElement('canvas');
// Scale down if too large to fit in 1MB limit safely
let { width, height } = img;
const maxSize = 1024;
if (width > maxSize || height > maxSize) {
const ratio = Math.min(maxSize / width, maxSize / height);
width = Math.round(width * ratio);
height = Math.round(height * ratio);
}
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
ctx?.drawImage(img, 0, 0, width, height);
resolve(canvas.toDataURL('image/webp', 0.8));
};
img.onerror = reject;
img.src = e.target?.result as string;
};
reader.onerror = reject;
reader.readAsDataURL(fileToClean);
});
const token = localStorage.getItem('auth_token') || '';
const newUrl = await editUVLayer("Remove the background and make it solid transparent or white. Also carefully remove all text, labels, logos, and stickers, keeping the product as a perfectly clean, plain, unbranded object.", base64, token);