skip to Main Content

enter image description here

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

2

Answers


  1. 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;
      }
    
    Login or Signup to reply.
  2. 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())
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search