firebase - 尝试将文件上传到 firebase 云存储时,TypeError : appImpl. 存储不是函数

标签 firebase flutter dart google-cloud-storage

我正在尝试将文件上传到 Firebase 存储,但我一直收到错误

 TypeError: appImpl.storage is not a function
at Object.getStorageInstance (http://localhost:61661/packages/firebase_storage_web/src/interop/storage.dart.lib.js:739:65)
at new firebase_storage_web.FirebaseStorageWeb.new (http://localhost:61661/packages/firebase_storage_web/src/reference_web.dart.lib.js:248:33)
at firebase_storage_web.FirebaseStorageWeb._nullInstance.delegateFor (http://localhost:61661/packages/firebase_storage_web/src/reference_web.dart.lib.js:203:14)
at Function.instanceFor (http://localhost:61661/packages/firebase_storage_platform_interface/src/platform_interface/platform_interface_task_snapshot.dart.lib.js:870:83)
at firebase_storage.FirebaseStorage.__.get [_delegate] (http://localhost:61661/packages/firebase_storage/firebase_storage.dart.lib.js:85:120)
at firebase_storage.FirebaseStorage.__.ref (http://localhost:61661/packages/firebase_storage/firebase_storage.dart.lib.js:125:58)
at importFile (http://localhost:61661/packages/denance/data_management.dart.lib.js:4737:53)
at importFile.next (<anonymous>)
at http://localhost:61661/dart_sdk.js:37445:33
at _RootZone.runUnary (http://localhost:61661/dart_sdk.js:37316:59)
at _FutureListener.thenAwait.handleValue (http://localhost:61661/dart_sdk.js:32551:29)
at handleValueCallback (http://localhost:61661/dart_sdk.js:33078:49)
at Function._propagateToListeners (http://localhost:61661/dart_sdk.js:33116:17)
at _Future.new.[_completeWithValue] (http://localhost:61661/dart_sdk.js:32964:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:61661/dart_sdk.js:32985:35)
at Object._microtaskLoop (http://localhost:61661/dart_sdk.js:37568:13)
at _startMicrotaskLoop (http://localhost:61661/dart_sdk.js:37574:13)
at http://localhost:61661/dart_sdk.js:33324:9

我不确定这个错误是什么,这是我的代码实现

 Future importFile() async {


    FilePickerResult ? result = await FilePicker.platform.pickFiles();

    if (result != null) {
        Uint8List fileBytes = result.files.first.bytes!;
        String fileName = result.files.first.name;

        FirebaseStorage storage = FirebaseStorage.instance;


        // Upload file
        await storage.ref('bigquery/$fileName').putData(fileBytes);
    }

这是我的 packag.json 供引用

version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
 
dev_dependencies:
  flutter_test:
    sdk: flutter
    
  http: ^0.13.3 
  cloud_firestore: ^2.3.0
  firebase_core: ^1.2.0
  flutter_staggered_grid_view: ^0.4.0
  syncfusion_flutter_charts: ^19.2.46
  random_string_generator: ^2.0.0
  file_picker: ^3.0.3
  firebase_storage: ^10.0.1 

  flutter_svg: ^0.22.0

................................................ ..................................................... ..................................................... ..................................................... ..................................................... …………

最佳答案

你必须像导入js文件一样

<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-storage.js"></script>

你可以在这里看到它flutter web TypeError: dart.global.firebase.storage is not a function

关于firebase - 尝试将文件上传到 firebase 云存储时,TypeError : appImpl. 存储不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68548035/

相关文章:

google-analytics - Firebase Analytics 键和值限制为 24 和 36 个字符

ios - firebase 删除值导致 tableview 重新加载双倍元素

Flutter ColorScheme 类背景颜色未显示在脚手架中

dart - Flutter创建无限ListView.builder上下滚动

syntax - Flutter 的小部件构造函数中的这种类似 JSON 的语法是什么?

class - 将List <object>添加到类

ios - 如何使用 swift3 从 ios 设备触发 firebase 的推送通知

firebase - Nuxt.js 应用中初始化 Firebase 的位置

animation - Flutter:Hero transition + widget animation 同时进行?

firebase - 用户使用Firebase注册时如何保存名称?