Use media url instead of reference url when picking movie types in image 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 https://github.com/facebook/react-native/pull/5771

Reviewed By: svcscm

Differential Revision: D2905720

Pulled By: nicklockwood

fb-gh-sync-id: 4b0200652c3b6a62cdb65deb582fbc5829c577a6
shipit-source-id: 4b0200652c3b6a62cdb65deb582fbc5829c577a6
This commit is contained in:
Ryan Linton 2016-02-09 04:44:43 -08:00 committed by facebook-github-bot-5
parent 855d411321
commit c6366e4dd8
1 changed files with 17 additions and 19 deletions

View File

@ -104,26 +104,24 @@ RCT_EXPORT_METHOD(openSelectDialog:(NSDictionary *)config
- (void)imagePickerController:(UIImagePickerController *)picker - (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info
{ {
// Image from PhotoLibrary NSString *mediaType = info[UIImagePickerControllerMediaType];
NSString *imageUri = [info[UIImagePickerControllerReferenceURL] absoluteString]; BOOL isMovie = [mediaType isEqualToString:(NSString *)kUTTypeMovie];
if (imageUri) { NSString *key = isMovie ? UIImagePickerControllerMediaURL : UIImagePickerControllerReferenceURL;
[self _dismissPicker:picker args:@[imageUri]]; NSURL *imageURL = info[key];
if (imageURL) {
} else { [self _dismissPicker:picker args:@[imageURL.absoluteString]];
// Image from CameraRoll hasn't uri. return;
// 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]];
}];
} }
// 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 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker