Home > OS >  while uploading image to firebase, this one error is always comes whatever i do
while uploading image to firebase, this one error is always comes whatever i do

Time:01-27

enter image description here

what went wrong? even if i replace the XFile into File, same error comes at this putFile.

CodePudding user response:

try this convert that xfile to file

uploadImages(XFile? pathsw) async {
    final paths = path.basename(pathsw!.path);
    final pathStorage =
        "${NAMEFOLDER}/${PATHNAME}/$paths";
   /// Start looking from here then so on
    final file = File(pathsw.path);
    final reference = FirestoreService.storage.ref().child(pathStorage);
    final task = reference.putFile(file);
    final snap = await task.whenComplete(() {});
    final url = await snap.ref.getDownloadURL();
    return url;
  }

CodePudding user response:

If you see, .putFile() takes in a element of File type. And you're accepting of type XFile. To convert:

File uploadImage = File(image!.path)

now the best way to upload would be to use .putFile() or .putData()

Your .putFile() implementation looks great, if you want to use .putData(), find the following code:

await reference.putData(uploadImage.readAsBytesSync())
  • Related