flutter_image_compress
flutter_image_compress copied to clipboard
compressAndGetFile on Android when keepExif = true
I'm using the path_provider plugin to determine the path the file need to be saved to. I'm calling getTemporaryDirectory to get the directory, and pass that into compressAndGetFile to save the file.
But the function is not returning anything.
This is to get the path
Future<String> get _localPath async {
final directory = await getTemporaryDirectory();
return directory.path;
}
This is to compress the image
Future<File> compressAndGetFile(String filePath, String targetPath) async {
var result = await FlutterImageCompress.compressAndGetFile(
filePath,
targetPath,
minHeight: MIN_HEIGHT,
minWidth: MIN_WIDTH,
quality: QUALITY,
format: CompressFormat.jpeg,
keepExif: true,
);
return result;
}
This is what i call
String localPath = await _localPath;
String filePath = await asset.filePath;
File file = await compressAndGetFile(filePath, '$localPath/$fileName');
The values for local and filepaths are: local: /data/user/0/com.spaza.curato/cache file: /storage/emulated/0/Download/gettyimages-1094874726.png
Need more info. Any log from console or logcat?
It looks like the issue is only applicable when you select keepExif=true. When i set this to false it works as expected. I updated the title of the issue to reflect this.
When keepExif = true the following warning is shown: W/ExifInterface(16945): Stop reading file since a wrong offset may cause an infinite loop: 0
Can you send your error picture as an attachment here?
Look like #81 .
Same issue here, any update?
Facing the same issue guys, any update on the fix?
Hey, just had the same issue on version 0.7.0. I was trying to set the target path as this:
var tempDir = await getTemporaryDirectory();
var target = '${tempDir.path}/image_compress/${file.name}';
Then i tried removing the image_compress from the path, and it worked. No idea about how, but it did. It ended up like this:
var tempDir = await getTemporaryDirectory();
var target = '${tempDir.path}/${file.name}';
Hey, just had the same issue on version 0.7.0. I was trying to set the target path as this:
var tempDir = await getTemporaryDirectory();var target = '${tempDir.path}/image_compress/${file.name}';Then i tried removing the image_compress from the path, and it worked. No idea about how, but it did. It ended up like this:
var tempDir = await getTemporaryDirectory();var target = '${tempDir.path}/${file.name}';
Just solved the first problem I was having. Apparently, the directory has to exist. If it doesn't, you get a null file on compress. So, I'm now first checking if the dir exists; if not, I create it recursively; if it does, everything goes as planned.