fluttercandies / flutter_photo_manager

A Flutter plugin that provides images, videos, and audio abstraction management APIs without interface integration, available on Android, iOS, macOS and OpenHarmony.
https://pub.dev/packages/photo_manager
Apache License 2.0
691 stars 314 forks source link

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

Open leonardocustodio opened 4 years ago

leonardocustodio commented 4 years ago

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?

CaiJingLong commented 4 years ago

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

leonardocustodio commented 4 years ago

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 :)

quickratio commented 3 years ago

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