Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting an error Argument type 'Uint8List' can't be assigned to the parameter type 'File'

I was trying to upload my image in firebase storage and got the error The argument type ‘Uint8List’ can’t be assigned to the parameter type ‘File’. I am a beginner. Here is my code, please help me resolving this issue.

Future<String> uploadImageToStorage(
      Uint8List image, String productUid) async {
    Reference storageRef = storage.ref().child('products').child(productUid);
    UploadTask uploadFile = storageRef.putFile(image);
    TaskSnapshot taskSnapshot = await uploadFile;
    Future<String> imageUrl = taskSnapshot.ref.getDownloadURL();

    return imageUrl;
  }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Change the putFile() to putData() and pass the image. Here is an updated code, let me know if this works for you.

Future<String> uploadImageToStorage(
      Uint8List image, String productUid) async {
    Reference storageRef = storage.ref().child('products').child(productUid);
    UploadTask uploadFile = storageRef.putData(image);
    TaskSnapshot taskSnapshot = await uploadFile;
    Future<String> imageUrl = taskSnapshot.ref.getDownloadURL();

    return imageUrl;
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading