0

enter image description here

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

Ruchit
  • 2,137
  • 1
  • 9
  • 24
palani
  • 13
  • 5

2 Answers2

0

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;
  }
Arbiter Chil
  • 1,061
  • 1
  • 6
  • 9
0

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())
Delwinn
  • 891
  • 4
  • 19