diff --git a/src/components/upload/PhotoUpload.tsx b/src/components/upload/PhotoUpload.tsx index 195f14c7..85371389 100644 --- a/src/components/upload/PhotoUpload.tsx +++ b/src/components/upload/PhotoUpload.tsx @@ -113,29 +113,41 @@ export function PhotoUpload({ } // Step 3: Poll for upload completion and get final URLs - const maxAttempts = 30; // 30 seconds maximum wait + const maxAttempts = 60; // 30 seconds maximum wait with faster polling let attempts = 0; while (attempts < maxAttempts) { - const { data: statusData, error: statusError } = await supabase.functions.invoke('upload-image', { - method: 'GET', - body: { id } - }); - - if (!statusError && statusData?.success && statusData.uploaded && statusData.urls) { - const imageUrl = isAvatar ? statusData.urls.avatar : statusData.urls.original; - const thumbUrl = isAvatar ? statusData.urls.avatar : statusData.urls.thumbnail; + try { + // Use direct fetch with URL parameters instead of supabase.functions.invoke with body + const response = await fetch(`https://ydvtmnrszybqnbcqbdcy.supabase.co/functions/v1/upload-image?imageId=${encodeURIComponent(id)}`, { + method: 'GET', + headers: { + 'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token}`, + 'Content-Type': 'application/json' + } + }); - return { - id: statusData.id, - url: imageUrl, - filename: file.name, - thumbnailUrl: thumbUrl - }; + if (response.ok) { + const statusData = await response.json(); + + if (statusData?.success && statusData.uploaded && statusData.urls) { + const imageUrl = isAvatar ? statusData.urls.avatar : statusData.urls.original; + const thumbUrl = isAvatar ? statusData.urls.avatar : statusData.urls.thumbnail; + + return { + id: statusData.id, + url: imageUrl, + filename: file.name, + thumbnailUrl: thumbUrl + }; + } + } + } catch (error) { + console.error('Status poll error:', error); } - // Wait 1 second before checking again - await new Promise(resolve => setTimeout(resolve, 1000)); + // Wait 500ms before checking again (faster polling) + await new Promise(resolve => setTimeout(resolve, 500)); attempts++; }