From b432a147b85b44906d3f570eb9ac5a7692b04280 Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Fri, 29 Sep 2017 15:50:16 +0100 Subject: [PATCH] [storage][ios] Convert HEI images to JPEG before upload --- ios/RNFirebase/storage/RNFirebaseStorage.m | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ios/RNFirebase/storage/RNFirebaseStorage.m b/ios/RNFirebase/storage/RNFirebaseStorage.m index 42f6a626..8bd00f60 100644 --- a/ios/RNFirebase/storage/RNFirebaseStorage.m +++ b/ios/RNFirebase/storage/RNFirebaseStorage.m @@ -221,8 +221,22 @@ RCT_EXPORT_METHOD(putFile:(NSString *) appName options.networkAccessAllowed = true; [[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) { if (info[PHImageErrorKey] == nil) { - firmetadata.contentType = [self utiToMimeType:dataUTI]; - [self uploadData:appName data:imageData firmetadata:firmetadata path:path resolver:resolve rejecter:reject]; + if (UTTypeConformsTo((__bridge CFStringRef)dataUTI, kUTTypeJPEG)) { + firmetadata.contentType = [self utiToMimeType:dataUTI]; + [self uploadData:appName data:imageData firmetadata:firmetadata path:path resolver:resolve rejecter:reject]; + } else { + // if the image UTI is not JPEG then convert to JPEG, e.g. HEI + CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); + NSDictionary *imageInfo = (__bridge NSDictionary*)CGImageSourceCopyPropertiesAtIndex(source, 0, NULL); + NSDictionary *imageMetadata = [imageInfo copy]; + NSMutableData *imageDataJPEG = [NSMutableData data]; + CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)imageDataJPEG, kUTTypeJPEG, 1, NULL); + CGImageDestinationAddImageFromSource(destination, source, 0, (__bridge CFDictionaryRef)imageMetadata); + CGImageDestinationFinalize(destination); + // Manually set mimetype to JPEG + firmetadata.contentType = @"image/jpeg"; + [self uploadData:appName data:[NSData dataWithData:imageDataJPEG] firmetadata:firmetadata path:path resolver:resolve rejecter:reject]; + } } else { reject(@"storage/request-image-data-failed", @"Could not obtain image data for the specified file.", nil); }