Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add size and format options when uploading an asset library image #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions RCTFileTransfer.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,24 @@ - (void)uploadAssetsLibrary:(NSDictionary *)input callback:(RCTResponseSenderBlo
[library assetForURL:assetUrl resultBlock:^(ALAsset *asset) {

ALAssetRepresentation *rep = [asset defaultRepresentation];
UIImage *image;
NSString *size = input[@"size"];
NSString *format = input[@"format"];

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;
if ([format isEqualToString:@"JPEG"]) {
fileData = UIImageJPEGRepresentation(image, 1);
} else {
fileData = UIImagePNGRepresentation(image);
}

[self sendData:fileData withOptions:input callback:callback];

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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
format, // either 'PNG' (default) or 'JPEG', only applies to asset library uploads
uploadUrl,
fileName,
mimeType,
Expand Down