diff --git a/README.md b/README.md index 05bb8dfee..6a938ca29 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,7 @@ Returns a Promise which when resolved will be of the following shape: * `group_name`: {string} * `image`: {object} : An object with the following shape: * `uri`: {string} + * `filename`: {string} * `height`: {number} * `width`: {number} * `isStored`: {boolean} diff --git a/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java b/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java index b859e5c83..104da7f3c 100644 --- a/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java +++ b/android/src/main/java/com/reactnativecommunity/cameraroll/CameraRollModule.java @@ -401,7 +401,10 @@ public class CameraRollModule extends ReactContextBaseJavaModule { int mimeTypeIndex) { WritableMap image = new WritableNativeMap(); Uri photoUri = Uri.parse("file://" + media.getString(dataIndex)); + File file = new File(media.getString(dataIndex)); + String strFileName = file.getName(); image.putString("uri", photoUri.toString()); + image.putString("filename", strFileName); float width = media.getInt(widthIndex); float height = media.getInt(heightIndex); diff --git a/ios/RNCCameraRollManager.m b/ios/RNCCameraRollManager.m index 2d256e10b..52d557f16 100644 --- a/ios/RNCCameraRollManager.m +++ b/ios/RNCCameraRollManager.m @@ -230,13 +230,13 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params } // Get underlying resources of an asset - this includes files as well as details about edited PHAssets - if ([mimeTypes count] > 0) { - NSArray *const assetResources = [PHAssetResource assetResourcesForAsset:asset]; - if (![assetResources firstObject]) { - return; - } + NSArray *const assetResources = [PHAssetResource assetResourcesForAsset:asset]; + if (![assetResources firstObject]) { + return; + } + PHAssetResource *const _Nonnull resource = [assetResources firstObject]; - PHAssetResource *const _Nonnull resource = [assetResources firstObject]; + if ([mimeTypes count] > 0) { CFStringRef const uti = (__bridge CFStringRef _Nonnull)(resource.uniformTypeIdentifier); NSString *const mimeType = (NSString *)CFBridgingRelease(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)); @@ -272,6 +272,7 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params ? @"audio" : @"unknown"))); CLLocation *const loc = asset.location; + NSString *const origFilename = resource.originalFilename; // A note on isStored: in the previous code that used ALAssets, isStored // was always set to YES, probably because iCloud-synced images were never returned (?). @@ -286,6 +287,7 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params @"group_name": currentCollectionName, @"image": @{ @"uri": uri, + @"filename": origFilename, @"height": @([asset pixelHeight]), @"width": @([asset pixelWidth]), @"isStored": @YES, // this field doesn't seem to exist on android