Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get file path of Asset #2

Open
mubashardev opened this issue Mar 5, 2023 · 2 comments
Open

Get file path of Asset #2

mubashardev opened this issue Mar 5, 2023 · 2 comments

Comments

@mubashardev
Copy link

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
Copy link
Owner

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants