Free Support Forum - aspose.cloud

Correcting OMR template with Aspose.OMR Cloud SDK for PHP

Hi I am using Aspose OMR cloud from PHP and getting the following error while correction process:
both omr and png files are present in root folder of dropbox. Then why is this error coming?
Is there any documentation available for error codes?
{
“Status”: “OK”,
“ErrorCode”: 1,
“ErrorText”: “Request processing caused an exception. Check files uploaded correctly and try again. Template 219 does not exists. Error reference ID 30d8b7c7-90c3-404b-82c4-5271c0a04a5a”,
“Payload”: {
“Result”: {
“TemplateId”: “”,
“ExecutionTime”: 0,
“ResponseFiles”: [],
“Info”: {
“ProcessedTasksCount”: 0,
“SuccessfulTasksCount”: 0,
“Details”: {
“RecognitionStatistics”: []
}
}
}
},
“ServerStat”: {
“StorageDownloadTime”: “00:00:00.5781106”,
“OmrFunctionCallTime”: “00:00:00.6211473”
}
}

My code:
$serializeFiles = function(array $filePaths) {
$files = [];
foreach ($filePaths as $filePath)
$files[] = [ ‘Name’ => basename($filePath)
, ‘Size’ => filesize($filePath)
, ‘Data’ => base64_encode(file_get_contents($filePath))];
return json_encode([‘Files’ => $files]);
};
$pngFile = $tModel->t_id.".png";

$param = new \Aspose\Omr\Model\OMRFunctionParam();
$param->setFunctionParam($serializeFiles([Yii::getAlias("@webroot/uploads/").$omrModel->omr_file_omr]));
$corrResponse = $omr->postRunOmrTask($pngFile, “CorrectTemplate”, $param, “XStore”, $folder);
$templateId = $corrResponse->getPayload()->getResult()->getTemplateId();

@ankurgupta555

Thanks for your inquiry. Apparently, error message tells that source documents are missing. However, can you please check error details from https://dashboard.aspose.cloud/#/usage and confirm. It will help us to address your issue exactly. Please also double check the $folder value, in case of storage root path it should be null.

It says:

Success: Run specific OMR task. name '219.png',actionName 'CorrectTemplate',param 'Aspose.Omr.Cloud.DTO.OMRFunctionParam',storage 'XStore',folder ''

What is a source document? omr file or png file or txt file? I have placed all three files in the root folder of my dropbox.

Folder value is null

@ankurgupta555

Source documents mean image file and template file(.omr). Please note PostRunOmrTask method accepts image file from cloud storage and template file from local file system as request body. So please double check you are passing file paths correctly, especially template file path. Please check PHP example to correct template for details.

So you mean
OMR and PNG files should be located on root folder (If $folder is null) of cloud storage. They are present there.
and OMR file ad request body from local file system. The following line is pointing to the correct file path of OMR file in local file system:
Yii::getAlias("@webroot/uploads/").$omrModel->omr_file_omr
Because file_get_contents is able to fetch data from the above path.

Dropbox Screenshot
screenshot.jpg (38.5 KB)

@ankurgupta555

Template(.omr) should be on local file system and PNG file on cloud storage. PHP demo is working fine at our end. Please double check .omr template exists on your local file system path. If the issue persist then please share your complete working code here. We will further investigate the issue.

`files.zip (48.9 KB)

<?php use Aspose\Omr\Api\OmrApi; require_once('vendor/autoload.php'); require_once('Storage.php'); error_reporting(E_ALL); ini_set("display_errors","On"); validateTemplate(); function validateTemplate(){ include "config.php"; $storage = new Storage($appKey, $appSid, $basePath); $omr = new OmrApi($appKey, $appSid); try { $param = new Aspose\Omr\Model\OMRFunctionParam(); $param->setFunctionParam(serializeFiles(["./new/omr_219.omr"])); $corrResponse = $omr->postRunOmrTask("219.png", "CorrectTemplate", $param, "XStore"); print_r($corrResponse); $templateId = $corrResponse->getPayload()->getResult()->getTemplateId(); foreach($corrResponse->getPayload()->getResult()->getResponseFiles() as $file){ file_put_contents("./new/".$file->getName(), base64_decode($file->getData())); } echo $templateId; } catch (Exception $exc) { echo $exc->getMessage(); exit(); } } function serializeFiles(array $filePaths) { $files = []; foreach ($filePaths as $filePath) $files[] = [ 'Name' => basename($filePath) , 'Size' => filesize($filePath) , 'Data' => base64_encode(file_get_contents($filePath))]; return json_encode(['Files' => $files]); }`

@ankurgupta555

Thanks for sharing the source documents and sample code. We are looking into it and will update you soon.

@ankurgupta555

We have investigated and noticed the reported issue. We have logged a ticket OMRCLOUD-27 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

Any updates?

@ankurgupta555

Thanks for your inquiry. I’m afraid we can’t share any update at the moment because issue is pending in the queue for investigation. We will share update with you asap.

It has been 6 days since I have shared the code and files. Is there any response from support?

@ankurgupta555

Thanks for your patience. We have planned the investigation of the issue and will update you soon with the results.

@ankurgupta555

Thanks for your patience. We have investigated the issue and noticed issue caused by the fact that template and image has different names: omr_219.omr and 219.png. They must share the same name, i.e. omr_219.omr and omr_219.png. Renaming and re-uploading the image with same name as the template results in successful validation.

There is a convention that template files and template image files that belong to the template share the same name. This rule is supported by the fact that:

  • Template generation produces two files (OMR and PNG) with the same name
  • creating template via Aspose.OMR Client also produces two files with the same name
  • PHP demo also runs using same logic So, unless user renames any of the file manually, this naming convention is supported by default.

Thank you. My problem resolved. My application is completed. But I have noticed an strange thing…

When we upload normal images taken from mobile camera on your desktop OMR client, it recognizes the questions and answers. But when we upload similar images from PHP using API it does not recognizes them. For API it requires higher contract images. Why is this difference?

This image is recognized by API
works.jpg (268.7 KB)

This kind of images are not recognized by API however while using through Desktop Client it recognizes them.
doesnotwork.jpg (2.4 MB)

@ankurgupta555

Thanks for your feedback. We are investigating(OMRCLOUD-28) your reported issue and will update you shortly.

@ankurgupta555

Thanks for your patience. We have tested your shared image(doesnotwork.jpg) with PHP SDK and unable to notice any issue MyTemplate.zip (2.5 MB). Please share your sample code along with other reources files. We will investigate it further.

Furthermore, please note OMR Client is an example and we pre-process image in it by compressing images and reduce their size. However it is out of the scope of OMR API. User can pre-process as per their requirement.