Skip to content

Commit

Permalink
feat(lib): Filename added to the image properties iOS and Android (#61)
Browse files Browse the repository at this point in the history
* fix(lib): mirror fix PHAsset video upload

facebook/react-native@458e70c#diff-3a2b7a4c4ebe5ac224b5a32896c032fb

* Include the filename in both iOS and Android

* Add filename to docs
  • Loading branch information
edwardmsmith authored and bartolkaruza committed Jun 13, 2019
1 parent 829c7bd commit f420cef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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}
Expand Down
Expand Up @@ -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);

Expand Down
14 changes: 8 additions & 6 deletions ios/RNCCameraRollManager.m
Expand Up @@ -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<PHAssetResource *> *const assetResources = [PHAssetResource assetResourcesForAsset:asset];
if (![assetResources firstObject]) {
return;
}
NSArray<PHAssetResource *> *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));

Expand Down Expand Up @@ -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 (?).
Expand All @@ -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
Expand Down

0 comments on commit f420cef

Please sign in to comment.