feat(lib): Filename added to the image properties iOS and Android (#61)

* fix(lib): mirror fix PHAsset video upload

458e70c79d (diff-3a2b7a4c4ebe5ac224b5a32896c032fb)

* Include the filename in both iOS and Android

* Add filename to docs
This commit is contained in:
Edward Smith 2019-06-13 01:24:46 -05:00 committed by Bartol Karuza
parent 829c7bd65a
commit f420cefa77
3 changed files with 12 additions and 6 deletions

View File

@ -143,6 +143,7 @@ Returns a Promise which when resolved will be of the following shape:
* `group_name`: {string} * `group_name`: {string}
* `image`: {object} : An object with the following shape: * `image`: {object} : An object with the following shape:
* `uri`: {string} * `uri`: {string}
* `filename`: {string}
* `height`: {number} * `height`: {number}
* `width`: {number} * `width`: {number}
* `isStored`: {boolean} * `isStored`: {boolean}

View File

@ -401,7 +401,10 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
int mimeTypeIndex) { int mimeTypeIndex) {
WritableMap image = new WritableNativeMap(); WritableMap image = new WritableNativeMap();
Uri photoUri = Uri.parse("file://" + media.getString(dataIndex)); 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("uri", photoUri.toString());
image.putString("filename", strFileName);
float width = media.getInt(widthIndex); float width = media.getInt(widthIndex);
float height = media.getInt(heightIndex); float height = media.getInt(heightIndex);

View File

@ -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 // 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];
NSArray<PHAssetResource *> *const assetResources = [PHAssetResource assetResourcesForAsset:asset]; if (![assetResources firstObject]) {
if (![assetResources firstObject]) { return;
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); CFStringRef const uti = (__bridge CFStringRef _Nonnull)(resource.uniformTypeIdentifier);
NSString *const mimeType = (NSString *)CFBridgingRelease(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)); NSString *const mimeType = (NSString *)CFBridgingRelease(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));
@ -272,6 +272,7 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params
? @"audio" ? @"audio"
: @"unknown"))); : @"unknown")));
CLLocation *const loc = asset.location; CLLocation *const loc = asset.location;
NSString *const origFilename = resource.originalFilename;
// A note on isStored: in the previous code that used ALAssets, isStored // 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 (?). // 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, @"group_name": currentCollectionName,
@"image": @{ @"image": @{
@"uri": uri, @"uri": uri,
@"filename": origFilename,
@"height": @([asset pixelHeight]), @"height": @([asset pixelHeight]),
@"width": @([asset pixelWidth]), @"width": @([asset pixelWidth]),
@"isStored": @YES, // this field doesn't seem to exist on android @"isStored": @YES, // this field doesn't seem to exist on android