@@ -392,9 +392,64 @@ + (NSString *)getTaskStatus:(FIRStorageTaskStatus)status {
392
392
}
393
393
}
394
394
395
- + (FIRStorageMetadata *)buildMetadataFromMap : (NSDictionary *)metadata {
396
- FIRStorageMetadata *storageMetadata = [[FIRStorageMetadata alloc ] initWithDictionary: metadata];
397
- storageMetadata.customMetadata = [metadata[@" customMetadata" ] mutableCopy ];
395
+ + (FIRStorageMetadata *)buildMetadataFromMap : (NSDictionary *)metadata
396
+ existingMetadata : (nullable FIRStorageMetadata *)existingMetadata {
397
+ // If an existing metadata was passed in, modify it with our map, otherwise init a fresh copy
398
+ FIRStorageMetadata *storageMetadata = existingMetadata;
399
+ if (storageMetadata == nil ) {
400
+ storageMetadata = [[FIRStorageMetadata alloc ] init ];
401
+ }
402
+
403
+ if (metadata[@" cacheControl" ] == [NSNull null ]) {
404
+ storageMetadata.cacheControl = nil ;
405
+ } else {
406
+ storageMetadata.cacheControl = metadata[@" cacheControl" ];
407
+ }
408
+
409
+ if (metadata[@" contentLanguage" ] == [NSNull null ]) {
410
+ storageMetadata.contentLanguage = nil ;
411
+ } else {
412
+ storageMetadata.contentLanguage = metadata[@" contentLanguage" ];
413
+ }
414
+
415
+ if (metadata[@" contentEncoding" ] == [NSNull null ]) {
416
+ storageMetadata.contentEncoding = nil ;
417
+ } else {
418
+ storageMetadata.contentEncoding = metadata[@" contentEncoding" ];
419
+ }
420
+
421
+ if (metadata[@" contentDisposition" ] == [NSNull null ]) {
422
+ storageMetadata.contentDisposition = nil ;
423
+ } else {
424
+ storageMetadata.contentDisposition = metadata[@" contentDisposition" ];
425
+ }
426
+
427
+ if (metadata[@" contentType" ] == [NSNull null ]) {
428
+ storageMetadata.contentType = nil ;
429
+ } else {
430
+ storageMetadata.contentType = metadata[@" contentType" ];
431
+ }
432
+
433
+ if (metadata[@" customMetadata" ] == [NSNull null ]) {
434
+ storageMetadata.customMetadata = @{};
435
+ } else {
436
+ NSMutableDictionary *customMetadata = [metadata[@" customMetadata" ] mutableCopy ];
437
+ for (NSString *key in customMetadata.allKeys ) {
438
+ if (customMetadata[key] == [NSNull null ] || customMetadata[key] == nil ) {
439
+ [customMetadata removeObjectForKey: key];
440
+ }
441
+ }
442
+ storageMetadata.customMetadata = customMetadata;
443
+ }
444
+
445
+ // md5hash may be settable but is not update-able, so just test for existence and carry it in
446
+ // FIXME this will need a fix related to
447
+ // https://github.com/firebase/firebase-ios-sdk/issues/9849#issuecomment-1159292592 if
448
+ // (metadata[@"md5hash"]) {
449
+ // NSLog(@"STORAGE md5hash was set");
450
+ // storageMetadata.md5Hash = metadata[@"md5hash"];
451
+ // }
452
+
398
453
return storageMetadata;
399
454
}
400
455
@@ -418,7 +473,9 @@ + (NSArray *)getErrorCodeMessage:(NSError *)error {
418
473
message = @" The specified device file path is invalid or is restricted." ;
419
474
} else {
420
475
if (userInfo[@" ResponseBody" ]) {
421
- message = [NSString stringWithFormat: @" An unknown error has occurred. (underlying reason '%@ ')" , userInfo[@" ResponseBody" ]];
476
+ message =
477
+ [NSString stringWithFormat: @" An unknown error has occurred. (underlying reason '%@ ')" ,
478
+ userInfo[@" ResponseBody" ]];
422
479
} else {
423
480
message = @" An unknown error has occurred." ;
424
481
}
0 commit comments