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;
}
CodePudding user response:
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;
}