I would like to know why i get this error when I try to upload an image.
class StorageRepository {
FirebaseStorage storage = FirebaseStorage.instanceFor(
bucket:
'', (Edit: The link was only wrong)
);
Future<String> uploadFile(File file) async {
var userUID = getCurrentUsersUID();
var storageRef = storage.ref().child("user/profile/$userUID");
UploadTask uploadTask = storageRef.putFile(file);
String downloadUrl = await (await uploadTask).ref.getDownloadURL();
userInstance.avatarUrl = downloadUrl;
return downloadUrl;
}
}
This is my method:
onPressed: () async {
var image = await ImagePicker().getImage(source: ImageSource.gallery);
var imageFile = File(image.path);
StorageRepository().uploadFile(imageFile);
setState(() {
});
},
Error Message:
E/flutter (20967): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(firebase_storage, The storage Uri cannot contain a path element., {}, null)