diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts index b5a336157..43f787ac9 100644 --- a/web/apps/photos/src/services/upload/uploadService.ts +++ b/web/apps/photos/src/services/upload/uploadService.ts @@ -656,13 +656,22 @@ async function tryExtractImageMetadata( fileTypeInfo: FileTypeInfo, lastModifiedMs: number, ): Promise { + let file: File; + if (fileOrPath instanceof File) { + file = fileOrPath; + } else { + const path = fileOrPath; + // The library we use for extracting EXIF from images, exifr, doesn't + // support streams. But unlike videos, for images it is reasonable to + // read the entire stream into memory here. + const { response } = await readStream(ensureElectron(), path); + file = new File([await response.arrayBuffer()], basename(path), { + lastModified: lastModifiedMs, + }); + } + try { - if (!(fileOrPath instanceof File)) { - fileOrPath = new File([await fileOrPath.blob()], fileOrPath.name, { - lastModified: lastModifiedMs, - }); - } - return await parseImageMetadata(fileOrPath, fileTypeInfo); + return await parseImageMetadata(file, fileTypeInfo); } catch (e) { log.error(`Failed to extract image metadata for ${fileOrPath}`, e); return undefined;