From 05212ffff692b3664834cb13c7dce99744d5c2b9 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 10 Sep 2025 14:43:18 +0300 Subject: [PATCH] Closes #4477 - Fix stripping location data away from raw images when processing them for upload --- .../Services/Media/MediaUploadingPreprocessor.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ElementX/Sources/Services/Media/MediaUploadingPreprocessor.swift b/ElementX/Sources/Services/Media/MediaUploadingPreprocessor.swift index 459e561d6..f4519ee2a 100644 --- a/ElementX/Sources/Services/Media/MediaUploadingPreprocessor.swift +++ b/ElementX/Sources/Services/Media/MediaUploadingPreprocessor.swift @@ -316,9 +316,15 @@ struct MediaUploadingPreprocessor { let metadataKeysToRemove = [kCGImagePropertyGPSDictionary: kCFNull] let data = NSMutableData() - guard let destination = CGImageDestinationCreateWithData(data as CFMutableData, type.identifier as CFString, count, nil) else { + + // Certain type identifiers cannot be used for image destinations, fall + // back to `public.jpeg` when that's the case + let destination = CGImageDestinationCreateWithData(data as CFMutableData, type.identifier as CFString, count, nil) ?? + CGImageDestinationCreateWithData(data as CFMutableData, UTType.jpeg.identifier as CFString, count, nil) + guard let destination else { throw .failedStrippingLocationData } + CGImageDestinationAddImageFromSource(destination, imageSource, 0, metadataKeysToRemove as NSDictionary) CGImageDestinationFinalize(destination)