使用 ImagePicker 从图库中选择的图像未上传到 Firebase 存储

Image selected from gallery with ImagePicker is not uploading to Firebase Storage

我有这样的代码:

Future pickImage() async {
    try {
      var image = await ImagePicker().pickImage(source: ImageSource.gallery);
      if(image == null) return;
      final imageTemp = File(image.path);

      setState(() {
        _image = imageTemp;
        print("file: " + image.toString()); // I/flutter (20502): file: Instance of 'XFile'
        print("file: " + image.path); // I/flutter (20502): file: /data/user/0/io.bolataktar.com/cache/image_picker1927171545041404148.jpg

      });
      final mountainsRef = storageRef.child(image.path);
    } catch (e) {
      print(e);
    }
  }

在这段代码中,我进入了画廊,我可以从那里 select 图片。但是在 selecting 图像之后,我希望它上传到 Firebase 存储。但是图像没有上传到 Firebase 存储。为什么会这样?我没有收到任何错误。


按照@user18309290 所说的进行操作后:

代码:

try {
  var image = await ImagePicker().pickImage(source: ImageSource.gallery);
  if(image == null) return;
  final imageTemp = File(image.path);

  setState(() {
    _image = imageTemp;
    print("file: " + image.toString()); // I/flutter (20502): file: Instance of 'XFile'
    print("file: " + image.path); // I/flutter (20502): file: /data/user/0/io.bolataktar.com/cache/image_picker1927171545041404148.jpg

  });
  final mountainsRef = storageRef.child(image.path);
  await mountainsRef.putFile(imageTemp); // added
} catch (e) {
  print(e);
}

错误:

W/.bolataktar.co(20502): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
E/flutter (20502): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method Task#startPutFile on channel plugins.flutter.io/firebase_storage)
E/flutter (20502): #0      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:175
E/flutter (20502): <asynchronous suspension>
E/flutter (20502):
I/flutter (20502): MissingPluginException(No implementation found for method Task#startPutFile on channel plugins.flutter.io/firebase_storage)

缺少上传部分。

  await mountainsRef.putFile(imageTemp);