gpt4 book ai didi

firebase - Flutter Firebase 存储不工作 : no default bucket

转载 作者:行者123 更新时间:2023-12-05 00:43:11 36 4
gpt4 key购买 nike

我正在尝试使用此功能将 pdf-file 上传到 Firebase-Storage:

  static Future<String> savePdf({
required Uint8List assetAsUint8List,
required String fileName,
required DocumentType documentType,
}) async {
String path =
'${BackendService().keys.studs}/${AuthenticationService().currentUser?.uid}/${documentType.name}/$fileName';

await FirebaseStorage.instanceFor().ref(path).putData(
assetAsUint8List,
);
return FirebaseStorage.instance.ref(path).getDownloadURL();
}

但这会失败并出现此错误:

Unhandled Exception: [firebase_storage/no-bucket] No default storage bucket could be found. Ensure you have correctly followed the Getting Started guide.

我在 main 中像这样 configure 我的应用程序:

Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: kIsWeb || Platform.isAndroid
? FirebaseOptions(
apiKey: "my-api-key",
appId: "my-app-id",
messagingSenderId: "my-messaing-sender-id",
projectId: "appflug",
)
: null,
);
runApp(
const App(),
);
}

它实际上在 iOS 上运行!但不在 Android 或网络上...

我遵循了文档,但它根本不起作用...我找不到任何有用的东西!

我在这里错过了什么?

如果您需要更多信息,请告诉我!

最佳答案

解决方案相当简单:我需要在 FirebaseOptions 中添加 storageBucket,所以我的 main 看起来像这样:

Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: kIsWeb || Platform.isAndroid
? FirebaseOptions(
apiKey: "my-app-key",
appId: "my-app-id",
messagingSenderId: "my-messaging-sender-id",
projectId: "my-project-id",
storageBucket: "myapp.appspot.com",
)
: null,
);
runApp(
const App(),
);
}

关于firebase - Flutter Firebase 存储不工作 : no default bucket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70763172/

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