flutter_image_compress icon indicating copy to clipboard operation
flutter_image_compress copied to clipboard

compressAndGetFile on Android when keepExif = true

Open Theunodb opened this issue 6 years ago • 8 comments
trafficstars

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

Theunodb avatar Oct 02 '19 13:10 Theunodb

Need more info. Any log from console or logcat?

CaiJingLong avatar Oct 08 '19 01:10 CaiJingLong

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

Theunodb avatar Oct 09 '19 09:10 Theunodb

Can you send your error picture as an attachment here?

CaiJingLong avatar Oct 09 '19 11:10 CaiJingLong

Look like #81 .

CaiJingLong avatar Oct 09 '19 12:10 CaiJingLong

Same issue here, any update?

algodave avatar Jan 08 '20 09:01 algodave

Facing the same issue guys, any update on the fix?

MohsinN avatar Jan 08 '20 09:01 MohsinN

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}';

EvertonMJunior avatar Mar 25 '21 17:03 EvertonMJunior

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.

EvertonMJunior avatar Mar 25 '21 17:03 EvertonMJunior