I’m building a simple system to let the user upload their profile picture into their account. When they click on the widget it runs this function:
XFile? xFileImage;
File? image;
Future pickImage() async {
try {
xFileImage = await ImagePicker().pickImage(
source: ImageSource.gallery,
imageQuality: 70,
);
if (xFileImage == null) return;
final File imageFile = File(xFileImage!.path);
setState(() {
image = imageFile;
});
} on PlatformException catch (error) {
print(error);
}
}
This function works fine. However, when I try to upload the image on Firebase Storage, the app throws this error:
[firebase_storage/unknown] The operation couldn’t be completed. Message too long
Here is the code snippet I use to upload the image on Firebase:
if (image != null) {
final FirebaseStorage storage = FirebaseStorage.instance;
await storage.ref().child('users/${state.user.userId}')
.putFile(image!);
}
I followed each step written in the Firebase Storage documentation, but I’m missing something.