Skip to content

Commit

Permalink
Use media url instead of reference url when picking movie types in im…
Browse files Browse the repository at this point in the history
…age picker

Summary:
I ran into an issue trying to upload videos selected with ImagePickerIOS to S3. The file would upload just fine but would be reduced in size and have no duration. It appears to be just a thumbnail of the video. Using the media url resolves this.
Closes #5771

Reviewed By: svcscm

Differential Revision: D2905720

Pulled By: nicklockwood

fb-gh-sync-id: 4b0200652c3b6a62cdb65deb582fbc5829c577a6
shipit-source-id: 4b0200652c3b6a62cdb65deb582fbc5829c577a6
  • Loading branch information
ryanlntn authored and facebook-github-bot-5 committed Feb 9, 2016
1 parent 855d411 commit c6366e4
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions Libraries/CameraRoll/RCTImagePickerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,24 @@ - (dispatch_queue_t)methodQueue
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info
{
// Image from PhotoLibrary
NSString *imageUri = [info[UIImagePickerControllerReferenceURL] absoluteString];
if (imageUri) {
[self _dismissPicker:picker args:@[imageUri]];

} else {
// Image from CameraRoll hasn't uri.
// We need to save it to the store first.
UIImage *originalImage = info[UIImagePickerControllerOriginalImage];

// WARNING: Using imageStoreManager causes memory leak
// because image isn't removed from store once we're done using it
[_bridge.imageStoreManager storeImage:originalImage withBlock:^(NSString *tempImageTag) {
if (!tempImageTag) {
[self _dismissPicker:picker args:nil];
return;
}
[self _dismissPicker:picker args:@[tempImageTag]];
}];
NSString *mediaType = info[UIImagePickerControllerMediaType];
BOOL isMovie = [mediaType isEqualToString:(NSString *)kUTTypeMovie];
NSString *key = isMovie ? UIImagePickerControllerMediaURL : UIImagePickerControllerReferenceURL;
NSURL *imageURL = info[key];
if (imageURL) {
[self _dismissPicker:picker args:@[imageURL.absoluteString]];
return;
}

// This is a newly taken image, and doesn't have a URL yet.
// We need to save it to the image store first.
UIImage *originalImage = info[UIImagePickerControllerOriginalImage];

// WARNING: Using ImageStoreManager may cause a memory leak because the
// image isn't automatically removed from store once we're done using it.
[_bridge.imageStoreManager storeImage:originalImage withBlock:^(NSString *tempImageTag) {
[self _dismissPicker:picker args:tempImageTag ? @[tempImageTag] : nil];
}];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
Expand Down

0 comments on commit c6366e4

Please sign in to comment.