我对Flutter和Firebase都是新手,所以请您原谅。我尝试使用Flutter Firebase存储插件上传文件到Firebase存储时遇到以下异常:
java.lang.IllegalArgumentException: The storage Uri cannot contain a path element.
下面附上更多信息。
D/FirebaseApp(17988): com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): java.lang.IllegalArgumentException: The storage Uri cannot contain a path element.
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at com.google.firebase.storage.FirebaseStorage.zza(Unknown Source:24)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at com.google.firebase.storage.FirebaseStorage.getInstance(Unknown Source:37)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at io.flutter.plugins.firebase.storage.FirebaseStoragePlugin.onMethodCall(FirebaseStoragePlugin.java:53)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:191)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at android.os.MessageQueue.next(MessageQueue.java:379)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at android.os.Looper.loop(Looper.java:144)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at android.app.ActivityThread.main(ActivityThread.java:7425)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
E/MethodChannel#plugins.flutter.io/firebase_storage(17988): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
我的上传代码与Flutter Firebase存储插件示例中的代码相似,如下所示。只是异常在执行倒数第二行时抛出(也就是下面代码的最后一行永远不会被执行,因为异常已经被抛出)。
final FirebaseStorage storage = new FirebaseStorage(
app: app, storageBucket: 'gs://myAppId.appspot.com/someCollection');
final StorageReference ref = storage.ref().child(basename(file.path));
var upload = ref.putFile(file);
final Uri downloadUri = (await upload.future).downloadUrl;
final downloadUrl = downloadUri.toString();
需要任何帮助都很感激!