Below is an end-to-end example of submitting an ExtractAAMVAID request using Perl programming language:
# Simple script to make and process the results of an ExtractAAMVAID request to the LEADTOOLS CloudServices.
# In order to run this script, the following changes will need to be added:
# 1) Place your Application ID in the $appId variable.
# 2) Place your Application Password in the $password variable
# The script will perform the following operations in order:
# 1)Perform an ExtractAAMVAID request to the LEADTOOLS CloudServices. A successfully made request will return a unique identifier.
# 2)We will then query the services using the GUID -- if the file is finished processing, the body will contain all the
# request data.
# 3)We will take the json data that was returned, parse it, and display all the information that was returned.
#
#
# This script makes use of the following Perl libraries:
# 1) Http-Message - http://search.cpan.org/~oalders/HTTP-Message-6.15/
# 2) libwww-perl - http://search.cpan.org/~oalders/libwww-perl-6.33/
# 3) JSON-Parse - http://search.cpan.org/~bkb/JSON-Parse-0.55/
# 4) Try-Tiny - http://search.cpan.org/~ether/Try-Tiny-0.30/
use base 'HTTP::Message';
use HTTP::Request::Common;
use LWP::UserAgent ();
use JSON::Parse ':all';
use Try::Tiny;
require HTTP::Request;
require HTTP::Headers;
my $servicesUrl = "https://azure.leadtools.com/api/";
#The first page in the file to mark for processing
my $firstPage = 1;
#Sending a value of -1 will indicate to the services that the rest of the pages in the file should be processed.
my $lastPage = -1;
my $appId = 'Replace with Application ID';
my $password = 'Replace with Application Password';
my $servicesUrl = "http://552da7f3710a45a69b374a1daabe818c.cloudapp.net/api/";
my $appId = 'unittestid';
my $password = 'A_K|}y-.P8*Uw7iP2S.KzqmL';
#If uploading via a URL, the Content_length needs to be set to 0.
#If you are passing a file as multi-part content, the Content_Length does not need to be predefined.
my $headers = HTTP::Headers->new(
Content_Length => 0
);
$headers->authorization_basic($appId, $password);
#The User Agent to be used when making requests
my $ua = LWP::UserAgent->new;
#We will be uploading the file via a URL. Files can also be passed by adding a PostFile to the request. Only 1 file will be accepted per request.
#The services will use the following priority when determining what a request is trying to do GUID > URL > Request Body Content
my $fileURL = 'http://demo.leadtools.com/images/cloud_samples/aamva_sample.png';
my $recognitionUrl = $servicesUrl . 'Recognition/ExtractAAMVAID?firstPage=' . $firstPage . '&lastPage=' . $lastPage . '&fileurl=' . $fileURL;
my $request = POST $recognitionUrl,
Content =>[];
#If uploading a file as multi-part content:
#my $recognitionUrl = $servicesUrl . 'Recognition/ExtractAAMVAID?firstPage=' . $firstPage . '&lastPage=' . $lastPage;
#my $request = POST $recognitionUrl,
# Content_Type => 'form-data',
# Content=>[
# FILE => [ "path/to/input/file" ]
# ];
$request->authorization_basic($appId, $password);
my $response = $ua->request($request);
if(!$response->is_success){
print STDERR $response->status_line, "\n";
exit;
}
my $guid = $response->decoded_content;
print("Unique ID returned by the services: " . $guid . "\n");
my $queryUrl = $servicesUrl . 'Query?id=' . $guid;
while(true){
$request = HTTP::Request->new(POST => $queryUrl, $headers);
$response = $ua->request($request);
$returnedData = parse_json($response->decoded_content);
if($returnedData->{'FileStatus'} != 100 && $returnedData->{'FileStatus'} != 123){
last;
}
sleep(5);
}
print("File finished processing with file status: " . $returnedData->{'FileStatus'} . "\n");
try{
# The file did not process successfully. Refer to our documentation for the full list of File Statuses and their associated meanings.
if($returnedData->{'FileStatus'} != 200){
exit;
}
print("Results: \n");
$parsedResponse = $returnedData->{'RequestData'};
foreach my $serviceResults (@@$parsedResponse){
print "Service Type: " . $serviceResults->{'ServiceType'} . "\n";
print "Recognition Type: ". $serviceResults->{'RecognitionType'} . "\n";
my @@data = @@{$serviceResults->{'data'}};
foreach my $ammvaObj (@@data){
for $role (keys %$ammvaObj){
print "$role=$ammvaObj->{$role} \n";
}
}
}
}catch{
print "Failed to parse JSON: " . Perl ExtractAAMVAID Tutorial
Below is an end-to-end example of submitting an ExtractAAMVAID request using Perl programming language:
;
}