【问题标题】:TypeError: appImpl.storage is not a function when trying to upload a file to firebase cloud storageTypeError:appImpl.storage 在尝试将文件上传到 Firebase 云存储时不是一个函数
【发布时间】:2021-10-03 11:09:46
【问题描述】:

我正在尝试将文件上传到 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

.................................................. ..................................................... ..................................................... ..................................................... ..................................................... .........

【问题讨论】:

    标签: firebase flutter dart google-cloud-storage


    【解决方案1】:

    你必须像a一样导入js文件

    &lt;script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-storage.js"&gt;&lt;/script&gt;

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-21
      • 2019-12-18
      • 2020-04-23
      • 2023-02-24
      • 2022-01-08
      • 1970-01-01
      相关资源
      最近更新 更多