Below is an end-to-end example of submitting an ExtractAAMVAID request using PHP programming language:
<?php
// 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 in the GeneratePostOptions method
// 2) Place your Application Password in the $password variable in the GeneratePostOptions method
//
// 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.
$servicesBaseUrl = "https://azure.leadtools.com/api/";
//The first page in the file to mark for processing
$firstPage = 1;
//Sending a value of -1 will indicate to the services that the rest of the pages in the file should be processed.
$lastPage = -1;
//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
$fileURL = 'http://demo.leadtools.com/images/cloud_samples/aamva_sample.png';
$baseRecognitionURL = '%sRecognition/ExtractAAMVAID?firstPage=%s&lastPage=%s&fileurl=%s';
$formattedRecognitionURL = sprintf($baseRecognitionURL, $servicesBaseUrl, $firstPage, $lastPage, $fileURL);
/*
If uploading a file alongside the HTTP request:
$baseRecognitionURL = '%sRecognition/ExtractAAMVAID?firstPage=%s&lastPage=%s';
$formattedRecognitionURL = sprintf($baseRecognitionURL, $servicesBaseUrl, $firstPage, $lastPage);
*/
//Generate the CURL options to be used
$recognitionRequestOptions = GeneratePostOptions($formattedRecognitionURL);
$request = curl_init();
curl_setopt_array($request, $recognitionRequestOptions); //Set the request URL
if (!$guid = curl_exec($request)) {
echo "There was an error processing the request. \n\r";
echo $guid;
exit;
}
curl_close($request); //Close the request
echo "Unique ID returned by the services: $guid \n\r";
echo "Querying Results...\n\r";
$baseQueryURL = '%sQuery?id=%s';
$formattedQueryURL = sprintf($baseQueryURL, $servicesBaseUrl, $guid);
$queryRequestOptions = GeneratePostOptions($formattedQueryURL);
while (true) { //Poll the services to determine if the request has finished processing.
$request = curl_init();
curl_setopt_array($request, $queryRequestOptions); //Set the request URL
if (!$results = curl_exec($request)) {
echo "There was an error querying the services \n\r";
echo $results;
curl_close($request);
exit;
}
curl_close($request);
$decodedResponse = json_decode($results);
$fileStatus = $decodedResponse->{'FileStatus'};
if ($fileStatus != 100 && $fileStatus != 123) {
//The file has finished processing
break;
}
sleep(5); //If the file hasn't finished processing, we will wait 5 seconds before checking again.
}
echo "File finished processing with file status: " . $fileStatus . "\n\r";
//The file did not process successfully. Refer to our documentation for the full list of File Statuses and their associated meanings.
if ($fileStatus != 200) {
exit;
}
echo "Results: \n\r";
//Decode and parse the JSON results.
$jsonArray = $decodedResponse->{'RequestData'};
foreach ($jsonArray as $serviceResults) {
echo "Service Type: " . $serviceResults->{'ServiceType'} . "\n\r";
echo "Recognition Type: " . $serviceResults->{'RecognitionType'} . "\n\r";
$data = $serviceResults->{'data'};
foreach($data as $ammvaObj){
foreach (get_object_vars($ammvaObj) as $key => $value){
echo $key . ": " . $value . "\n\r";
}
}
}
function GeneratePostOptions($url)
{
//Function to generate the array of CURL options to be used.
//If we are uploading via a URL, we will need to add a Content-Length:0 header value.
//If we are uploading a file as post data, we do not need to include the Content-Length header.
$appId = "Replace with Application ID";
$password = "Replace with Application Password";
//Remove if uploading the file as post data.
$headers = array(
"Content-Length : 0"
);
/*
//To upload a file as form data:
$file = new CURLFile("path/to/file");
$imageData = array('image' => $file);
//**NOTE** - Only 1 file will be accepted per request.
*/
$postOptions = array(
CURLOPT_POST => 1,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERPWD => "$appId:$password",
CURLOPT_FORBID_REUSE => 1,
//Uncomment if uploading as post data.
//CURLOPT_POSTFIELDS => $imageData,
//Comment out the CURLOPT_HTTPHEADER if uploading as post data.
CURLOPT_HTTPHEADER => $headers
);
return $postOptions;
}
?>