Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

How to get image file path from identifier in Asset? #17

Open
Miedziaq opened this issue Jan 18, 2022 · 4 comments
Open

How to get image file path from identifier in Asset? #17

Miedziaq opened this issue Jan 18, 2022 · 4 comments

Comments

@Miedziaq
Copy link

Hello,

I need to store file data to give users posibility to restart upload on failed.
But this library returns some Asset class with 'identifier', and this identifier cannot be reused to get the filebytes again,
how to convert it to filepath??

@hbali
Copy link

hbali commented Jan 22, 2022

@Miedziaq
Hi!

You need another library to access the path (flutter_absolute_path package).

I did it like this:

final images = await MultiImagePicker.pickImages(
        maxImages: 4,
        enableCamera: true);

    final files = List<File>();
    await Future.wait(images.map((e) async {
      final path = await FlutterAbsolutePath.getAbsolutePath(e.identifier);
      final file = File(path);
      files.add(file);
    }));
    return files;

@MRSEREY
Copy link

MRSEREY commented Mar 17, 2022

@Miedziaq is there any ways to convert File to Asset?

@hbrhbr
Copy link

hbrhbr commented Mar 21, 2022

@Miedziaq Hi!

You need another library to access the path (flutter_absolute_path package).

I did it like this:

final images = await MultiImagePicker.pickImages(
        maxImages: 4,
        enableCamera: true);

    final files = List<File>();
    await Future.wait(images.map((e) async {
      final path = await FlutterAbsolutePath.getAbsolutePath(e.identifier);
      final file = File(path);
      files.add(file);
    }));
    return files;

But this package don't support null-safety.

@Miedziaq
Copy link
Author

@Miedziaq is there any ways to convert File to Asset?

unfortunately i dont find any proper way to done it. only flutter_absolute_path like @hbrhbr mentioned but if you have newer project it not works. and i cannot solve my problem with this. another way is to save selected files to temp folder to have access to it and path then, but everything is to done manually by yourself..

finally i resign completely from this library and i switched to the other one without this problems :)

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

No branches or pull requests

4 participants