normalizeImageForUpload function

Future<String> normalizeImageForUpload(
  1. String filePath, {
  2. required bool isCamera,
})

Implementation

Future<String> normalizeImageForUpload(
  String filePath, {
  required bool isCamera,
}) async {
  if (!isCamera || kIsWeb || defaultTargetPlatform != TargetPlatform.iOS) {
    return filePath;
  }
  try {
    final temporaryDirectory = await getTemporaryDirectory();
    final targetPath =
        '${temporaryDirectory.path}/nim_avatar_${DateTime.now().microsecondsSinceEpoch}.jpg';
    final normalized = await FlutterImageCompress.compressAndGetFile(
      filePath,
      targetPath,
      format: CompressFormat.jpeg,
      quality: 90,
      autoCorrectionAngle: true,
      keepExif: false,
    );
    return normalized?.path ?? filePath;
  } catch (_) {
    return filePath;
  }
}