flutter_photo_manager icon indicating copy to clipboard operation
flutter_photo_manager copied to clipboard

[Feature] Create `AssetEntity` from `File` without saving to the gallery

Open leonardocustodio opened this issue 5 years ago • 3 comments
trafficstars

Is there anyway we could create an AssetEntity from a file?

My use case is: mainly the app loads photos from gallery but there are a few private files that are not in the gallery. They are in the application support directory.

I did not find a way to load this files, is that possible? Would be something that we could make with a few changes?

leonardocustodio avatar Sep 26 '20 21:09 leonardocustodio

It can be implemented in theory, but it is not in the main responsibility of this library.

CaiJingLong avatar Sep 27 '20 08:09 CaiJingLong

I understand it is not the responsibility of the library. But if we could make that would be awesome.

Because if we can't create an AssetEntity it gets way harder to manage the photo objects when having files loaded outside the gallery as we would require to make a custom object and verify if it is from the gallery or not and if it is return the AssetEntity if not return another object. Or encapsulate everything and stop using AssetEntity at all.

If anyone have a free time to make this PR I think it would be a really nice feature to have :)

leonardocustodio avatar Sep 28 '20 16:09 leonardocustodio

You probably found a solution by now, but just in case others are looking, give this a try, worked for me with assets.

final File file = your_file; // Your file object
final Uint8List byteData = await file.readAsBytes(); // Convert to Uint8List
final AssetEntity imageEntity = await PhotoManager.editor.saveImage(byteData); // Saved in the device then create an AssetEntity

Credit to the creator of this package: https://github.com/fluttercandies/flutter_wechat_assets_picker#create-assetentity-from-file-or-uint8list-rawdata

quickratio avatar Sep 01 '21 08:09 quickratio