From b46ef89ee6f3bb80069edcf10477a77015999788 Mon Sep 17 00:00:00 2001 From: Bruz Marzolf Date: Mon, 16 Nov 2015 09:58:56 -0800 Subject: [PATCH 1/2] Add a size option to allow full resolution upload --- RCTFileTransfer.m | 14 +++++++++++--- README.md | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/RCTFileTransfer.m b/RCTFileTransfer.m index ac9ee08..bffe2fc 100644 --- a/RCTFileTransfer.m +++ b/RCTFileTransfer.m @@ -51,10 +51,18 @@ - (void)uploadAssetsLibrary:(NSDictionary *)input callback:(RCTResponseSenderBlo [library assetForURL:assetUrl resultBlock:^(ALAsset *asset) { ALAssetRepresentation *rep = [asset defaultRepresentation]; + UIImage *image; + NSString *size = input[@"size"]; + + if ([size isEqualToString:@"full"]) { + CGImageRef imageRef = [rep fullResolutionImage]; + image = [UIImage imageWithCGImage:imageRef scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]]; + } else { + CGImageRef fullScreenImageRef = [rep fullScreenImage]; + image = [UIImage imageWithCGImage:fullScreenImageRef]; + } - CGImageRef fullScreenImageRef = [rep fullScreenImage]; - UIImage *image = [UIImage imageWithCGImage:fullScreenImageRef]; - NSData *fileData = UIImagePNGRepresentation(image); + NSData *fileData = UIImageJPEGRepresentation(image, 1); [self sendData:fileData withOptions:input callback:callback]; diff --git a/README.md b/README.md index 5389bd4..8ea1fda 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ When you properly add the `RCTFileTransfer.m` file to your xcode project you may var { NativeModules } = require('react-native'); var obj = { uri, // either an 'assets-library' url (for files from photo library) or an image dataURL + size, // either 'screen' (default) or 'full', only applies to asset library uploads uploadUrl, fileName, mimeType, From ed9aa2b80f76b2e6e3a75b9201522430deefd6fc Mon Sep 17 00:00:00 2001 From: Bruz Marzolf Date: Mon, 16 Nov 2015 10:06:57 -0800 Subject: [PATCH 2/2] Add a format option to allow upload as a JPEG --- RCTFileTransfer.m | 8 +++++++- README.md | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/RCTFileTransfer.m b/RCTFileTransfer.m index bffe2fc..0916307 100644 --- a/RCTFileTransfer.m +++ b/RCTFileTransfer.m @@ -53,6 +53,7 @@ - (void)uploadAssetsLibrary:(NSDictionary *)input callback:(RCTResponseSenderBlo ALAssetRepresentation *rep = [asset defaultRepresentation]; UIImage *image; NSString *size = input[@"size"]; + NSString *format = input[@"format"]; if ([size isEqualToString:@"full"]) { CGImageRef imageRef = [rep fullResolutionImage]; @@ -62,7 +63,12 @@ - (void)uploadAssetsLibrary:(NSDictionary *)input callback:(RCTResponseSenderBlo image = [UIImage imageWithCGImage:fullScreenImageRef]; } - NSData *fileData = UIImageJPEGRepresentation(image, 1); + NSData *fileData; + if ([format isEqualToString:@"JPEG"]) { + fileData = UIImageJPEGRepresentation(image, 1); + } else { + fileData = UIImagePNGRepresentation(image); + } [self sendData:fileData withOptions:input callback:callback]; diff --git a/README.md b/README.md index 8ea1fda..5c348a9 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ var { NativeModules } = require('react-native'); var obj = { uri, // either an 'assets-library' url (for files from photo library) or an image dataURL size, // either 'screen' (default) or 'full', only applies to asset library uploads + format, // either 'PNG' (default) or 'JPEG', only applies to asset library uploads uploadUrl, fileName, mimeType,