Skip to content

Commit

Permalink
Fix Android Firebase version and used named arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
collinjackson committed May 9, 2017
1 parent 7bde905 commit d5794a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 1 addition & 2 deletions android/build.gradle
Expand Up @@ -30,7 +30,6 @@ android {
disable 'InvalidPackage'
}
dependencies {
compile 'com.google.firebase:firebase-auth:9.0.0'
compile 'com.google.firebase:firebase-storage:9.0.0'
compile 'com.google.firebase:firebase-storage:10.2.1'
}
}
Expand Up @@ -22,32 +22,35 @@
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.MethodCall;

import java.util.List;
import java.util.Map;
import java.io.File;

/**
* FirebaseStoragePlugin
*/
public class FirebaseStoragePlugin implements MethodCallHandler {
private FlutterActivity activity;
private FirebaseStorage firebaseStorage;

public static FirebaseStoragePlugin register(FlutterActivity activity) {
return new FirebaseStoragePlugin(activity);
}

private FirebaseStoragePlugin(FlutterActivity activity) {
this.activity = activity;
FirebaseApp.initializeApp(activity);
this.firebaseStorage = FirebaseStorage.getInstance();
new MethodChannel(activity.getFlutterView(), "firebase_storage").setMethodCallHandler(this);
}

@Override
public void onMethodCall(MethodCall call, final Result result) {
if (call.method.equals("StorageReference#putFile")) {
List arguments = (List) call.arguments;
String filename = (String) arguments.get(0);
String path = (String) arguments.get(1);
Map<String, String> arguments = (Map<String, String>) call.arguments;
String filename = arguments.get("filename");
String path = arguments.get("path");
File file = new File(filename);
StorageReference ref = FirebaseStorage.getInstance().getReference().child(path);
StorageReference ref = firebaseStorage.getReference().child(path);
UploadTask uploadTask = ref.putFile(Uri.fromFile(file));
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
Expand Down
7 changes: 4 additions & 3 deletions ios/Classes/FirebaseStoragePlugin.m
Expand Up @@ -26,12 +26,13 @@ - (instancetype)initWithController:(FlutterViewController *)controller {
}
FlutterMethodChannel *channel =
[FlutterMethodChannel methodChannelWithName:@"firebase_storage"
binaryMessenger:controller];
binaryMessenger:controller];
[channel
setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
if ([@"StorageReference#putFile" isEqualToString:call.method]) {
NSData *data = [NSData dataWithContentsOfFile:call.arguments[0]];
NSString *path = call.arguments[1];
NSData *data =
[NSData dataWithContentsOfFile:call.arguments["filename"]];
NSString *path = call.arguments["path"];
FIRStorageReference *fileRef =
[[FIRStorage storage].reference child:path];
FIRStorageUploadTask *uploadTask = [fileRef
Expand Down
5 changes: 4 additions & 1 deletion lib/firebase_storage.dart
Expand Up @@ -40,7 +40,10 @@ class StorageUploadTask {
Future<Null> _start() async {
String downloadUrl = await FirebaseStorage._channel.invokeMethod(
"StorageReference#putFile",
<dynamic>[file.absolute.path, path],
<String, String>{
'filename': file.absolute.path,
'path': path,
},
);
_completer.complete(new UploadTaskSnapshot(downloadUrl: Uri.parse(downloadUrl)));
}
Expand Down

0 comments on commit d5794a1

Please sign in to comment.