From c9dba8a1b7acd24ad4692153b0c920c8b97f3090 Mon Sep 17 00:00:00 2001 From: Alex Kim Date: Tue, 2 Jun 2026 19:14:10 +1000 Subject: [PATCH] fix(downloads): poster images not showing for downloaded content --- hooks/useImageStorage.ts | 41 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/hooks/useImageStorage.ts b/hooks/useImageStorage.ts index ec66c5053..6b6101b55 100644 --- a/hooks/useImageStorage.ts +++ b/hooks/useImageStorage.ts @@ -1,3 +1,4 @@ +import { File, Paths } from "expo-file-system"; import { useCallback } from "react"; import { storage } from "@/utils/mmkv"; @@ -12,36 +13,32 @@ const useImageStorage = () => { } }, []); + /** + * expo-file-system instead of fetch+Blob+FileReader: the latter silently + * resolves to an empty payload under RN's New Architecture. + */ const image2Base64 = useCallback(async (url?: string | null) => { if (!url) return null; - let blob: Blob; + const tmpFile = new File( + Paths.cache, + `img-${Date.now()}-${Math.random().toString(36).slice(2)}.jpg`, + ); try { - // Fetch the data from the URL - const response = await fetch(url); - blob = await response.blob(); + const downloaded = await File.downloadFileAsync(url, tmpFile, { + idempotent: true, + }); + return await downloaded.base64(); } catch (error) { console.warn("Error fetching image:", error); return null; + } finally { + try { + if (tmpFile.exists) tmpFile.delete(); + } catch { + // best-effort cleanup + } } - - // Create a FileReader instance - const reader = new FileReader(); - - // Convert blob to base64 - return new Promise((resolve, reject) => { - reader.onloadend = () => { - if (typeof reader.result === "string") { - // Extract the base64 string (remove the data URL prefix) - const base64 = reader.result.split(",")[1]; - resolve(base64); - } else { - reject(new Error("Failed to convert image to base64")); - } - }; - reader.onerror = reject; - reader.readAsDataURL(blob); - }); }, []); const saveImage = useCallback(