diff --git a/README.md b/README.md index 05bb8dfee2..6a938ca292 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 b859e5c835..104da7f3c8 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 @@ private static boolean putImageInfo( 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 2d256e10b6..52d557f169 100644 --- a/ios/RNCCameraRollManager.m +++ b/ios/RNCCameraRollManager.m @@ -230,13 +230,13 @@ static void RCTResolvePromise(RCTPromiseResolveBlock resolve, } // 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 @@ static void RCTResolvePromise(RCTPromiseResolveBlock resolve, ? @"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 @@ static void RCTResolvePromise(RCTPromiseResolveBlock resolve, @"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