firebase - 使用 Flutter Firebase 存储插件上传文件

标签 firebase flutter firebase-storage

我是 Flutter 和 Firebase 的新手,所以请多多包涵。尝试使用 flutter firebase storage plugin 将文件上传到 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 storage plugin的例子中的相似。 ,并且可以在下面看到。在倒数第二行的执行期间抛出异常(即 - 由于抛出异常,下面代码中的最后一行从未执行)。

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();

感谢任何帮助!

最佳答案

使用

final FirebaseStorage storageRef = FirebaseStorage.instance.ref().child('someCollection');

final StorageReference ref = storageRef.child(basename(file.path));

关于firebase - 使用 Flutter Firebase 存储插件上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51921046/

相关文章:

node.js - 在作为 firebase 函数运行的 express 应用程序中获取完整的 url——包括函数名称?

ios - Firebase动态链接无法打开iOS应用

dart - flutter 中的启动画面实现

firebase - 使用唯一/随机名称存储文件

firebase - 如何禁用 Firebase 存储模拟器?

javascript - 如何在我的 Rails 应用程序中减小 firebase.js 的大小

javascript - typescript promise 数组在一种情况下正确解决但在另一种情况下不正确

plugins - 如何从我的简单 .dart 文件创建一个插件以在 Flutter 中使用?

flutter - 如何在 Flutter 中更改 CupertinoNavigationBar 中后退按钮的颜色

java - 如何从 Firebase 存储中检索图像 url 以进行 JSON 解析?