validateLocalMedia function

Future<PlatformResult<String>> validateLocalMedia(
  1. String? path
)

Implementation

Future<PlatformResult<String>> validateLocalMedia(String? path) async {
  if (path == null || path.trim().isEmpty) {
    return const PlatformResult.failure(PlatformFailure.invalidInput);
  }
  try {
    final local = path.startsWith('file:')
        ? Uri.parse(path).toFilePath()
        : path;
    final file = File(local);
    if (!await file.exists()) {
      return const PlatformResult.failure(PlatformFailure.fileNotFound);
    }
    if (await file.length() == 0) {
      return const PlatformResult.failure(PlatformFailure.emptyFile);
    }
    return PlatformResult.success(file.absolute.path);
  } catch (error) {
    return platformException(error);
  }
}