fixed ios custom metaData

This commit is contained in:
nico 2017-06-29 18:12:57 +02:00
parent d2f9958ca3
commit d77dd094db
1 changed files with 11 additions and 3 deletions

View File

@ -5,6 +5,7 @@
#import <Photos/Photos.h> #import <Photos/Photos.h>
#import "Firebase.h" #import "Firebase.h"
@implementation RNFirebaseStorage @implementation RNFirebaseStorage
RCT_EXPORT_MODULE(RNFirebaseStorage); RCT_EXPORT_MODULE(RNFirebaseStorage);
@ -154,7 +155,7 @@ RCT_EXPORT_METHOD(getMetadata: (NSString *) path resolver:(RCTPromiseResolveBloc
*/ */
RCT_EXPORT_METHOD(updateMetadata: (NSString *) path metadata:(NSDictionary *) metadata resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { RCT_EXPORT_METHOD(updateMetadata: (NSString *) path metadata:(NSDictionary *) metadata resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
FIRStorageReference *fileRef = [self getReference:path]; FIRStorageReference *fileRef = [self getReference:path];
FIRStorageMetadata *firmetadata = [[FIRStorageMetadata alloc] initWithDictionary:metadata]; FIRStorageMetadata *firmetadata = [self buildMetadataFromMap:metadata];
[fileRef updateMetadata:firmetadata completion:^(FIRStorageMetadata * _Nullable metadata, NSError * _Nullable error) { [fileRef updateMetadata:firmetadata completion:^(FIRStorageMetadata * _Nullable metadata, NSError * _Nullable error) {
if (error != nil) { if (error != nil) {
@ -317,14 +318,14 @@ RCT_EXPORT_METHOD(putFile:(NSString *) path localPath:(NSString *)localPath meta
- (void) uploadFile:(NSURL *) url metadata:(NSDictionary *) metadata path:(NSString *) path resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject { - (void) uploadFile:(NSURL *) url metadata:(NSDictionary *) metadata path:(NSString *) path resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
FIRStorageReference *fileRef = [self getReference:path]; FIRStorageReference *fileRef = [self getReference:path];
FIRStorageMetadata *firmetadata = [[FIRStorageMetadata alloc] initWithDictionary:metadata]; FIRStorageMetadata *firmetadata = [self buildMetadataFromMap:metadata];
FIRStorageUploadTask *uploadTask = [fileRef putFile:url metadata:firmetadata]; FIRStorageUploadTask *uploadTask = [fileRef putFile:url metadata:firmetadata];
[self addUploadObservers:uploadTask path:path resolver:resolve rejecter:reject]; [self addUploadObservers:uploadTask path:path resolver:resolve rejecter:reject];
} }
- (void) uploadData:(NSData *) data metadata:(NSDictionary *) metadata path:(NSString *) path resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject{ - (void) uploadData:(NSData *) data metadata:(NSDictionary *) metadata path:(NSString *) path resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject{
FIRStorageReference *fileRef = [self getReference:path]; FIRStorageReference *fileRef = [self getReference:path];
FIRStorageMetadata *firmetadata = [[FIRStorageMetadata alloc] initWithDictionary:metadata]; FIRStorageMetadata *firmetadata = [self buildMetadataFromMap:metadata];
FIRStorageUploadTask *uploadTask = [fileRef putData:data metadata:firmetadata]; FIRStorageUploadTask *uploadTask = [fileRef putData:data metadata:firmetadata];
[self addUploadObservers:uploadTask path:path resolver:resolve rejecter:reject]; [self addUploadObservers:uploadTask path:path resolver:resolve rejecter:reject];
} }
@ -394,6 +395,13 @@ RCT_EXPORT_METHOD(putFile:(NSString *) path localPath:(NSString *)localPath meta
}; };
} }
- (FIRStorageMetadata *)buildMetadataFromMap:(NSDictionary *)metadata {
NSMutableDictionary *result = [metadata mutableCopy];
result[@"metadata"] = metadata[@"customMetadata"];
[result removeObjectForKey:@"customMetadata"];
return [[FIRStorageMetadata alloc] initWithDictionary:result];
}
- (NSString *)getTaskStatus:(FIRStorageTaskStatus)status { - (NSString *)getTaskStatus:(FIRStorageTaskStatus)status {
if (status == FIRStorageTaskStatusResume || status == FIRStorageTaskStatusProgress) { if (status == FIRStorageTaskStatusResume || status == FIRStorageTaskStatusProgress) {
return @"running"; return @"running";