gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 07:00:25 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com