Home > Software design >  Image selected from gallery with ImagePicker is not uploading to Firebase Storage
Image selected from gallery with ImagePicker is not uploading to Firebase Storage

Time:05-13

I have a code like this:

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);
    }
  }

In this code I enter the gallery and I can select an image from there. But after selecting image I want it to upload to Firebase Storage. But the image is not uploading to Firebase Storage. Why could it be? I am not getting any errors.


After doing what @user18309290 said:

Code:

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);
}

Error:

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)

CodePudding user response:

The uploading part is missing.

  await mountainsRef.putFile(imageTemp);
  • Related