Converting file path to file in Flutter

Viewed 277

I am getting the path of an image from the device storage, like this:

path = res[0]?.path;
print("path:"+path);

The output of that print is:

/data/user/0/qplan/cache/image_picker_b432f88b-3146-4a99-9e8b-acbefd066e3a2471538209034937554.jpeg

I need to convert it to File in order to upload the image to Firestore Storage.

2 Answers

You can use this.

import 'dart:async';
import 'dart:io';

path = res[0]?.path;
File(path).readAsString().then((String contents) {
   print(contents);
});

You can get file inserting your path to File object as below;

File fileToUpload = new File(path);
Related