From 69b94ab7c017062f3d8c5f2b466268b197d6d5e6 Mon Sep 17 00:00:00 2001 From: billisdead Date: Sat, 16 May 2026 21:18:29 +0200 Subject: [PATCH] fix: use globalThis.fetch for image upload on Android expoFetch does not support the React Native FormData { uri, name, type } pattern. Switch upload request to globalThis.fetch which handles it correctly. Also propagate upload errors instead of swallowing them. Co-Authored-By: Claude Sonnet 4.6 --- .../postiz-mobile/app/(tabs)/compose.tsx | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/artifacts/postiz-mobile/app/(tabs)/compose.tsx b/artifacts/postiz-mobile/app/(tabs)/compose.tsx index 2ddc091..9fe2487 100644 --- a/artifacts/postiz-mobile/app/(tabs)/compose.tsx +++ b/artifacts/postiz-mobile/app/(tabs)/compose.tsx @@ -77,33 +77,32 @@ export default function ComposeScreen() { const removeImage = () => setImageUri(null); - const uploadImage = async (): Promise => { - if (!imageUri) return null; + const uploadImage = async (): Promise => { setUploading(true); try { const formData = new FormData(); if (Platform.OS === "web") { - const response = await expoFetch(imageUri); + const response = await expoFetch(imageUri!); const blob = await response.blob(); formData.append("file", blob, "upload.jpg"); } else { formData.append("file", { - uri: imageUri, + uri: imageUri!, name: "upload.jpg", type: "image/jpeg", } as unknown as Blob); } - const uploadRes = await expoFetch(`${baseUrl}/upload`, { + // eslint-disable-next-line no-undef + const uploadRes = await globalThis.fetch(`${baseUrl}/upload`, { method: "POST", headers: { Authorization: apiKey }, body: formData, }); - const data = await uploadRes.json() as PostizUploadResult; - return data; - } catch (e: unknown) { - const msg = e instanceof Error ? e.message : String(e); - Alert.alert("Upload Failed", `Could not upload image.\n${msg}`); - return null; + if (!uploadRes.ok) { + const raw = await uploadRes.text().catch(() => uploadRes.statusText); + throw new Error(`Upload HTTP ${uploadRes.status}: ${raw.slice(0, 200)}`); + } + return await uploadRes.json() as PostizUploadResult; } finally { setUploading(false); } @@ -125,9 +124,7 @@ export default function ComposeScreen() { let media: Array<{ id: string; path: string }> = []; if (imageUri) { const uploaded = await uploadImage(); - if (uploaded) { - media = [{ id: uploaded.id, path: uploaded.path }]; - } + media = [{ id: uploaded.id, path: uploaded.path }]; } const payload = { type: postNow ? "now" : "schedule",