uploadLivenessBatch method
Upload liveness verification files in batch
verificationId - The verification ID
files - List of liveness files (videos or image frames) - File on mobile, XFile on web
filesMetadata - List of metadata maps, each containing:
- movementType: LivenessMovementType (as string)
- livenessType: 'video' or 'frame'
- frameIndex: int (required for frame type, optional for video)
Returns SdkVerificationResponse
Implementation
Future<SdkVerificationResponse> uploadLivenessBatch({
required String verificationId,
required List<dynamic> files, // List of File on mobile, XFile on web
required List<Map<String, dynamic>> filesMetadata,
}) async {
try {
if (files.length != filesMetadata.length) {
throw ApexKycException(
'Number of files (${files.length}) must match number of metadata entries (${filesMetadata.length})',
);
}
// Create a map of files with field names (file0, file1, etc.)
final filesMap = <String, dynamic>{};
for (int i = 0; i < files.length; i++) {
filesMap['file$i'] = files[i];
}
// Prepare metadata as JSON string in fields
final fields = <String, String>{'files': jsonEncode(filesMetadata)};
final response = await _apiClient.postMultipartMultiple(
'/sdk/kyc-verification/verifications/$verificationId/liveness/batch',
files: filesMap,
fields: fields,
);
final jsonData = json.decode(response.body) as Map<String, dynamic>;
return SdkVerificationResponse.fromJson(jsonData);
} catch (e) {
if (e is ApexKycException) {
rethrow;
}
throw ApexKycException(
'Failed to upload liveness batch: ${e.toString()}',
originalError: e,
);
}
}