loic-hamdi / multiple_images_picker

MIT License
4 stars 14 forks source link

Get file path of Asset #2

Open mubashardev opened 1 year ago

mubashardev commented 1 year ago

How to get file path of a selected asset? I want to upload it to server as a file image. So how can I get it as File?

loic-hamdi commented 1 year ago

Hey @MicroProgramer

Here is an example:

final assets = await MultipleImagesPicker.pickImages(maxImages: 1);
if (assets.isNotEmpty && assets.first.originalHeight != null && assets.first.originalWidth != null) {
final temp = await Directory.systemTemp.createTemp();
final imageData = await assets.first.getByteData();
final File imageFile = await File('${temp.path}/img').writeAsBytes(imageData.buffer.asUint8List(imageData.offsetInBytes, imageData.lengthInBytes));
}

imageFile is then your image File

mubashardev commented 1 year ago

I know but my question is how to get path of the picked image instead of creating a temp file using image bytes. This is not a good approach if I choose multiple images. I'm just making their copies and compromising the space complexity. Please add an attribute for its exact path from where it was picked.