Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
szakarias committed Apr 23, 2018
1 parent bb4fdff commit e16ec70
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,25 @@ public void onFailure(@NonNull Exception e) {
});
}


private void updateMetadata(MethodCall call, final Result result) {
String path = call.argument("path");
Map<String, Object> metadata = call.argument("metadata");
StorageReference ref = firebaseStorage.getReference().child(path);
ref.updateMetadata(buildMetadataFromMap(metadata))
.addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
@Override
public void onSuccess(StorageMetadata storageMetadata) {
result.success(buildMapFromMetadata(storageMetadata));
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
result.error("metadata_error", e.getMessage(), null); }
});
.addOnSuccessListener(
new OnSuccessListener<StorageMetadata>() {
@Override
public void onSuccess(StorageMetadata storageMetadata) {
result.success(buildMapFromMetadata(storageMetadata));
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
result.error("metadata_error", e.getMessage(), null);
}
});
}

private void getDownloadUrl(MethodCall call, final Result result) {
Expand Down Expand Up @@ -198,7 +200,7 @@ private Map<String, Object> buildMapFromMetadata(StorageMetadata storageMetadata
map.put("contentEncoding", storageMetadata.getContentEncoding());
map.put("contentLanguage", storageMetadata.getContentLanguage());
map.put("contentType", storageMetadata.getContentType());
return map;
return map;
}

private void getData(MethodCall call, final Result result) {
Expand Down
14 changes: 7 additions & 7 deletions packages/firebase_storage/ios/Classes/FirebaseStoragePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ - (FIRStorageMetadata *)buildMetadataFromDictionary:(NSDictionary *)dictionary {
return metadata;
}

- (NSDictionary *)buildDictionaryFromMetadata:(FIRStorageMetadata *) metadata {
- (NSDictionary *)buildDictionaryFromMetadata:(FIRStorageMetadata *)metadata {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setValue:[metadata bucket] forKey:@"bucket"];
[dictionary setValue:[NSString stringWithFormat:@"%lld", [metadata generation]]
Expand Down Expand Up @@ -157,12 +157,12 @@ - (void)updateMetadata:(FlutterMethodCall *)call result:(FlutterResult)result {
FIRStorageReference *ref = [[FIRStorage storage].reference child:path];
[ref updateMetadata:[self buildMetadataFromDictionary:metadataDictionary]
completion:^(FIRStorageMetadata *metadata, NSError *error) {
if (error != nil) {
result(error.flutterError);
} else {
result([self buildDictionaryFromMetadata:metadata]);
}
}];
if (error != nil) {
result(error.flutterError);
} else {
result([self buildDictionaryFromMetadata:metadata]);
}
}];
}

- (void)getDownloadUrl:(FlutterMethodCall *)call result:(FlutterResult)result {
Expand Down
2 changes: 2 additions & 0 deletions packages/firebase_storage/lib/firebase_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class StorageReference {
}

/// Updates the metadata associated with this [StorageReference].
///
/// Returns a [Future] that will complete to the updated [StorageMetadata].
Future<StorageMetadata> updateMetadata(StorageMetadata metadata) async {
return new StorageMetadata._fromMap(await FirebaseStorage.channel
.invokeMethod("StorageReference#updateMetadata", <String, dynamic>{
Expand Down
34 changes: 29 additions & 5 deletions packages/firebase_storage/test/firebase_storage_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ void main() {
});
});


group('updateMetadata', () {
final List<MethodCall> log = <MethodCall>[];

Expand All @@ -96,7 +95,21 @@ void main() {
FirebaseStorage.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
return <String, String>{'name': 'image.jpg'};
switch (methodCall.method) {
case 'StorageReference#getMetadata':
return <String, String>{
'name': 'image.jpg',
};
break;
case 'StorageReference#updateMetadata':
return <String, String>{
'name': 'image.jpg',
'contentLanguage': 'en'
};
break;
default:
break;
}
});
ref = FirebaseStorage.instance
.ref()
Expand All @@ -106,24 +119,35 @@ void main() {
});

test('invokes correct method', () async {
await ref.getMetadata();
await ref.updateMetadata(const StorageMetadata(contentLanguage: 'en'));

expect(log, <Matcher>[
isMethodCall(
'StorageReference#updateMetadata',
arguments: <String, dynamic>{
'path': 'avatars/large/image.jpg',
'metadata': <String, String>{
'cacheControl': null,
'contentDisposition': null,
'contentLanguage': 'en',
'contentType': null,
'contentEncoding': null
},
},
),
]);
});

test('returns correct result', () async {
expect((await ref.getMetadata()).name, 'image.jpg');
expect((await ref.getMetadata()).contentLanguage, null);
expect(
(await ref.updateMetadata(
const StorageMetadata(contentLanguage: 'en')))
.contentLanguage,
'en');
});
});


group('getDownloadUrl', () {
final List<MethodCall> log = <MethodCall>[];

Expand Down

0 comments on commit e16ec70

Please sign in to comment.