Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/firebase_storage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.1+2

* On iOS, use `putFile` instead of `putData` appropriately to detect `Content-Type`.

## 2.1.1+1

* On iOS, gracefully handle the case of uploading a nonexistent file without crashing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void main() {
final String url = await ref.getDownloadURL();
final http.Response downloadData = await http.get(url);
expect(downloadData.body, kTestString);
expect(downloadData.headers['content-type'], 'text/plain');
final File tempFile = File('${systemTempDir.path}/tmp$uuid.txt');
if (tempFile.existsSync()) {
await tempFile.delete();
Expand Down
31 changes: 22 additions & 9 deletions packages/firebase_storage/ios/Classes/FirebaseStoragePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,30 +180,43 @@ - (void)getReferenceFromUrl:(FlutterMethodCall *)call result:(FlutterResult)resu
}

- (void)putFile:(FlutterMethodCall *)call result:(FlutterResult)result {
NSData *data = [NSData dataWithContentsOfFile:call.arguments[@"filename"]];
NSURL *fileUrl = [NSURL fileURLWithPath:call.arguments[@"filename"]];
[self
putHandler:^(FIRStorageReference *fileRef, FIRStorageMetadata *metadata) {
return [fileRef putFile:fileUrl metadata:metadata];
}
call:call
result:result];
}

- (void)putData:(FlutterMethodCall *)call result:(FlutterResult)result {
NSData *data = [(FlutterStandardTypedData *)call.arguments[@"data"] data];
if (data == nil) {
result([FlutterError errorWithCode:@"storage_error"
message:@"Failed to read file"
details:nil]);
return;
}
[self put:data call:call result:result];
}

- (void)putData:(FlutterMethodCall *)call result:(FlutterResult)result {
NSData *data = [(FlutterStandardTypedData *)call.arguments[@"data"] data];
[self put:data call:call result:result];
[self
putHandler:^(FIRStorageReference *fileRef, FIRStorageMetadata *metadata) {
return [fileRef putData:data metadata:metadata];
}
call:call
result:result];
}

- (void)put:(NSData *)data call:(FlutterMethodCall *)call result:(FlutterResult)result {
- (void)putHandler:(FIRStorageUploadTask * (^)(FIRStorageReference *fileRef,
FIRStorageMetadata *metadata))putHandler
call:(FlutterMethodCall *)call
result:(FlutterResult)result {
NSString *path = call.arguments[@"path"];
NSDictionary *metadataDictionary = call.arguments[@"metadata"];
FIRStorageMetadata *metadata;
if (![metadataDictionary isEqual:[NSNull null]]) {
metadata = [self buildMetadataFromDictionary:metadataDictionary];
}
FIRStorageReference *fileRef = [storage.reference child:path];
FIRStorageUploadTask *uploadTask = [fileRef putData:data metadata:metadata];
FIRStorageUploadTask *uploadTask = putHandler(fileRef, metadata);
NSNumber *handle = [NSNumber numberWithInt:_nextUploadHandle++];
[uploadTask observeStatus:FIRStorageTaskStatusSuccess
handler:^(FIRStorageTaskSnapshot *snapshot) {
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_storage/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Cloud Storage, a powerful, simple, and
cost-effective object storage service for Android and iOS.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_storage
version: 2.1.1+1
version: 2.1.1+2

flutter:
plugin:
Expand Down