Hello i was trying to get images from my pc to firebase storage . then saving the url and showing them through the firestore. code for defining
final FirebaseStorage _storage = FirebaseStorage.instance;
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
dynamic _imageFile;
String? _fileName = '';
pickImage() async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
allowMultiple: false,
type: FileType.custom,
allowedExtensions: ['jpg', 'png', 'jpeg'],
);
if (result != null) {
setState(() {
_imageFile = result.files.first.bytes;
_fileName = result.files.first.name;
});
}
}
_uploadbannerToStorage(dynamic image) async {
Reference ref = _storage.ref().child('Banners').child(_fileName!);
UploadTask uploadTask = ref.putData(image);
TaskSnapshot snapshot = await uploadTask;
String downloadURL = await snapshot.ref.getDownloadURL();
return downloadURL;
}
_uploadBannerToFirestore(String downloadURL) async {
if (_imageFile != null) {
String image = await _uploadbannerToStorage(_imageFile);
await _firestore.collection('Banners').doc(_fileName).set({
'image': image,
});
}
}
dependencies:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:file_picker/file_picker.dart';
import 'package:firebase_storage/firebase_storage.dart';
but I get this error everytime I try to save Image
The following TypeErrorImpl was thrown while handling a gesture: Expected a value of type 'String', but got one of type 'NativeUint8List'
I tried casting downloadURL but that doest help I also thought about using Image_picker but there is little to no support for web in it and my program is to be used primarily on web.