mirror of
https://github.com/status-im/react-native-image-crop-picker.git
synced 2025-02-23 19:08:12 +00:00
Add creation and modification date to response (#530)
* added creationDate and modificationDate to response object added modificationDate to Android response * Update Compression.m (#529) Addition of passthrough preset option Update README to include dates in response
This commit is contained in:
parent
a4a2247fef
commit
b59db6bffa
@ -129,6 +129,8 @@ ImagePicker.clean().then(() => {
|
|||||||
| size | number | Selected image size in bytes |
|
| size | number | Selected image size in bytes |
|
||||||
| data | base64 | Optional base64 selected file representation |
|
| data | base64 | Optional base64 selected file representation |
|
||||||
| exif | object | Extracted exif data from image. Response format is platform specific |
|
| exif | object | Extracted exif data from image. Response format is platform specific |
|
||||||
|
| creationDate (ios only) | string | UNIX timestamp when image was created |
|
||||||
|
| modificationDate | string | UNIX timestamp when image was last modified |
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
|
@ -463,6 +463,7 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Bitmap bmp = validateVideo(videoPath);
|
Bitmap bmp = validateVideo(videoPath);
|
||||||
|
long modificationDate = new File(videoPath).lastModified();
|
||||||
|
|
||||||
WritableMap video = new WritableNativeMap();
|
WritableMap video = new WritableNativeMap();
|
||||||
video.putInt("width", bmp.getWidth());
|
video.putInt("width", bmp.getWidth());
|
||||||
@ -470,6 +471,7 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
|
|||||||
video.putString("mime", mime);
|
video.putString("mime", mime);
|
||||||
video.putInt("size", (int) new File(videoPath).length());
|
video.putInt("size", (int) new File(videoPath).length());
|
||||||
video.putString("path", "file://" + videoPath);
|
video.putString("path", "file://" + videoPath);
|
||||||
|
video.putString("modificationDate", String.valueOf(modificationDate));
|
||||||
|
|
||||||
resultCollector.notifySuccess(video);
|
resultCollector.notifySuccess(video);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -532,12 +534,14 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
|
|||||||
File compressedImage = compression.compressImage(activity, options, path);
|
File compressedImage = compression.compressImage(activity, options, path);
|
||||||
String compressedImagePath = compressedImage.getPath();
|
String compressedImagePath = compressedImage.getPath();
|
||||||
BitmapFactory.Options options = validateImage(compressedImagePath);
|
BitmapFactory.Options options = validateImage(compressedImagePath);
|
||||||
|
long modificationDate = new File(path).lastModified();
|
||||||
|
|
||||||
image.putString("path", "file://" + compressedImagePath);
|
image.putString("path", "file://" + compressedImagePath);
|
||||||
image.putInt("width", options.outWidth);
|
image.putInt("width", options.outWidth);
|
||||||
image.putInt("height", options.outHeight);
|
image.putInt("height", options.outHeight);
|
||||||
image.putString("mime", options.outMimeType);
|
image.putString("mime", options.outMimeType);
|
||||||
image.putInt("size", (int) new File(compressedImagePath).length());
|
image.putInt("size", (int) new File(compressedImagePath).length());
|
||||||
|
image.putString("modificationDate", String.valueOf(modificationDate));
|
||||||
|
|
||||||
if (includeBase64) {
|
if (includeBase64) {
|
||||||
image.putString("data", getBase64StringFromFile(compressedImagePath));
|
image.putString("data", getBase64StringFromFile(compressedImagePath));
|
||||||
|
@ -169,7 +169,7 @@ RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
|
|||||||
exif = [info objectForKey:UIImagePickerControllerMediaMetadata];
|
exif = [info objectForKey:UIImagePickerControllerMediaMetadata];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self processSingleImagePick:chosenImageT withExif:exif withViewController:picker withSourceURL:self.croppingFile[@"sourceURL"] withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"]];
|
[self processSingleImagePick:chosenImageT withExif:exif withViewController:picker withSourceURL:self.croppingFile[@"sourceURL"] withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"] withCreationDate:self.croppingFile[@"creationDate"] withModificationDate:self.croppingFile[@"modificationDate"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
||||||
@ -399,7 +399,10 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
withHeight:[NSNumber numberWithFloat:track.naturalSize.height]
|
withHeight:[NSNumber numberWithFloat:track.naturalSize.height]
|
||||||
withMime:@"video/mp4"
|
withMime:@"video/mp4"
|
||||||
withSize:fileSizeValue
|
withSize:fileSizeValue
|
||||||
withData:nil]);
|
withData:nil
|
||||||
|
withCreationDate:forAsset.creationDate
|
||||||
|
withModificationDate:forAsset.modificationDate
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
completion(nil);
|
completion(nil);
|
||||||
}
|
}
|
||||||
@ -407,7 +410,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary*) createAttachmentResponse:(NSString*)filePath withExif:(NSDictionary*) exif withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename withWidth:(NSNumber*)width withHeight:(NSNumber*)height withMime:(NSString*)mime withSize:(NSNumber*)size withData:(NSString*)data {
|
- (NSDictionary*) createAttachmentResponse:(NSString*)filePath withExif:(NSDictionary*) exif withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename withWidth:(NSNumber*)width withHeight:(NSNumber*)height withMime:(NSString*)mime withSize:(NSNumber*)size withData:(NSString*)data withCreationDate:(NSDate*)creationDate withModificationDate:(NSDate*)modificationDate
|
||||||
|
{
|
||||||
return @{
|
return @{
|
||||||
@"path": filePath,
|
@"path": filePath,
|
||||||
@"sourceURL": (sourceURL) ? sourceURL : [NSNull null],
|
@"sourceURL": (sourceURL) ? sourceURL : [NSNull null],
|
||||||
@ -419,6 +423,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
@"size": size,
|
@"size": size,
|
||||||
@"data": (data) ? data : [NSNull null],
|
@"data": (data) ? data : [NSNull null],
|
||||||
@"exif": (exif) ? exif : [NSNull null],
|
@"exif": (exif) ? exif : [NSNull null],
|
||||||
|
@"creationDate:": (creationDate) ? [NSString stringWithFormat:@"%.0f", [creationDate timeIntervalSince1970]] : [NSNull null],
|
||||||
|
@"modificationDate": (modificationDate) ? [NSString stringWithFormat:@"%.0f", [modificationDate timeIntervalSince1970]] : [NSNull null],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -509,6 +515,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
withMime:imageResult.mime
|
withMime:imageResult.mime
|
||||||
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
||||||
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0]: nil
|
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0]: nil
|
||||||
|
withCreationDate:phAsset.creationDate
|
||||||
|
withModificationDate:phAsset.modificationDate
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
processed++;
|
processed++;
|
||||||
@ -568,7 +576,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
withViewController:imagePickerController
|
withViewController:imagePickerController
|
||||||
withSourceURL:[sourceURL absoluteString]
|
withSourceURL:[sourceURL absoluteString]
|
||||||
withLocalIdentifier:phAsset.localIdentifier
|
withLocalIdentifier:phAsset.localIdentifier
|
||||||
withFilename:[phAsset valueForKey:@"filename"]];
|
withFilename:[phAsset valueForKey:@"filename"]
|
||||||
|
withCreationDate:phAsset.creationDate
|
||||||
|
withModificationDate:phAsset.modificationDate];
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@ -585,7 +595,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
// when user selected single image, with camera or from photo gallery,
|
// when user selected single image, with camera or from photo gallery,
|
||||||
// this method will take care of attaching image metadata, and sending image to cropping controller
|
// this method will take care of attaching image metadata, and sending image to cropping controller
|
||||||
// or to user directly
|
// or to user directly
|
||||||
- (void) processSingleImagePick:(UIImage*)image withExif:(NSDictionary*) exif withViewController:(UIViewController*)viewController withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename {
|
- (void) processSingleImagePick:(UIImage*)image withExif:(NSDictionary*) exif withViewController:(UIViewController*)viewController withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename withCreationDate:(NSDate*)creationDate withModificationDate:(NSDate*)modificationDate {
|
||||||
|
|
||||||
if (image == nil) {
|
if (image == nil) {
|
||||||
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
|
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
|
||||||
@ -601,6 +611,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
self.croppingFile[@"sourceURL"] = sourceURL;
|
self.croppingFile[@"sourceURL"] = sourceURL;
|
||||||
self.croppingFile[@"localIdentifier"] = localIdentifier;
|
self.croppingFile[@"localIdentifier"] = localIdentifier;
|
||||||
self.croppingFile[@"filename"] = filename;
|
self.croppingFile[@"filename"] = filename;
|
||||||
|
self.croppingFile[@"creationDate"] = creationDate;
|
||||||
|
self.croppingFile[@"modifcationDate"] = modificationDate;
|
||||||
NSLog(@"CroppingFile %@", self.croppingFile);
|
NSLog(@"CroppingFile %@", self.croppingFile);
|
||||||
|
|
||||||
[self startCropping:image];
|
[self startCropping:image];
|
||||||
@ -626,7 +638,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
withHeight:imageResult.height
|
withHeight:imageResult.height
|
||||||
withMime:imageResult.mime
|
withMime:imageResult.mime
|
||||||
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
||||||
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : nil]);
|
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : nil
|
||||||
|
withCreationDate:creationDate
|
||||||
|
withModificationDate:modificationDate]);
|
||||||
}]];
|
}]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -748,7 +762,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
withHeight:imageResult.height
|
withHeight:imageResult.height
|
||||||
withMime:imageResult.mime
|
withMime:imageResult.mime
|
||||||
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
||||||
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : nil]);
|
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : nil
|
||||||
|
withCreationDate:self.croppingFile[@"creationDate"]
|
||||||
|
withModificationDate:self.croppingFile[@"modificationDate"]]);
|
||||||
}]];
|
}]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user