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:
parent
855d411321
commit
c6366e4dd8
|
@ -104,27 +104,25 @@ RCT_EXPORT_METHOD(openSelectDialog:(NSDictionary *)config
|
|||
- (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];
|
||||
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;
|
||||
}
|
||||
[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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue