Skip to content

Commit

Permalink
feat(ios): return fileSize of video on iOS (#1848)
Browse files Browse the repository at this point in the history
* feat(ios): return fileSize of video on iOS

* update docs
  • Loading branch information
helenaford committed Nov 10, 2021
1 parent 9247249 commit fb85cfd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ The `callback` will be called with a response object, refer to [The Response Obj
| uri | OK | OK | The file uri in app specific cache storage. Except when picking **video from Android gallery** where you will get read only content uri, to get file uri in this case copy the file to app specific storage using any react-native library |
| width | OK | OK | Image dimensions (photos only) |
| height | OK | OK | Image dimensions (photos only) |
| fileSize | OK | OK | The file size (photos only) |
| fileSize | OK | OK | The file size (except for videos on Android) |
| type | OK | OK | The file type (photos only) |
| fileName | OK | OK | The file name |
| duration | OK | OK | The selected video duration in seconds |
Expand Down
1 change: 1 addition & 0 deletions ios/ImagePickerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ -(NSMutableDictionary *)mapVideoToAsset:(NSURL *)url error:(NSError **)error {
asset[@"duration"] = [NSNumber numberWithDouble:CMTimeGetSeconds([AVAsset assetWithURL:videoDestinationURL].duration)];
asset[@"uri"] = videoDestinationURL.absoluteString;
asset[@"type"] = [ImagePickerUtils getFileTypeFromUrl:videoDestinationURL];
asset[@"fileSize"] = [ImagePickerUtils getFileSizeFromUrl:videoDestinationURL];

return asset;
}
Expand Down
2 changes: 2 additions & 0 deletions ios/ImagePickerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
+ (UIImage*)resizeImage:(UIImage*)image maxWidth:(float)maxWidth maxHeight:(float)maxHeight;

+ (NSString *) getFileTypeFromUrl:(NSURL *)url;

+ (NSString *) getFileSizeFromUrl:(NSURL *)url;

@end
13 changes: 13 additions & 0 deletions ios/ImagePickerUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ + (NSString *) getFileTypeFromUrl:(NSURL *)url {
return (__bridge_transfer NSString *)MIMEType;
}

+ (NSNumber *) getFileSizeFromUrl:(NSURL *)url {
NSError *attributesError;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[url path] error:&attributesError];
NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
long fileSize = [fileSizeNumber longLongValue];

if (attributesError) {
return nil;
}

return [NSNumber numberWithLong:fileSize];
}

+ (UIImage*)resizeImage:(UIImage*)image maxWidth:(float)maxWidth maxHeight:(float)maxHeight
{
if ((maxWidth == 0) || (maxHeight == 0)) {
Expand Down

0 comments on commit fb85cfd

Please sign in to comment.