getImageFiles method

Future<List<String>> getImageFiles(
  1. String host,
  2. String jobId,
  3. String directory
)

Saves images from a scan job to a directory.

host - The host server URL. jobId - The ID of the scan job. directory - The directory where images will be saved.

Returns a List<String> containing the paths of saved images.

Implementation

Future<List<String>> getImageFiles(
    String host, String jobId, String directory) async {
  final List<String> images = [];
  final url = '$host/DWTAPI/ScanJobs/$jobId/NextDocument';
  while (true) {
    try {
      final response = await http.get(Uri.parse(url));

      if (response.statusCode == 200) {
        final timestamp = DateTime.now().millisecondsSinceEpoch;
        final imagePath = join(directory, 'image_$timestamp.jpg');
        final file = File(imagePath);
        await file.writeAsBytes(response.bodyBytes);
        images.add(imagePath);
      } else if (response.statusCode == 410) {
        break;
      }
    } catch (error) {
      break;
    }
  }

  return images;
}