Recognize Barcode Images with Aspose.BarCode REST API Throws 502 Bad Gateway Error

Hello! Some images are recognized normally, and after some the answer comes: Exception when calling BarcodeApi->postBarcodeRecognizeFromUrlOrContent: [502] Server error: POST https://api.aspose.cloud/v3.0/barcode/recognize?preset=HighPerformance resulted in a 502 Bad Gateway response:

502 Bad Gateway

502 Bad Gateway


ngin (truncated...)

@antonurakov

Please try to set an explicit barcode type hint for the respective barcode type. Hopefully, it will resolve the issue. However, if the issue persists, then kindly share your problematic images with us for investigation.

Thanks I will try, but i didn’t find a documentation, i find only:
$request->type = Aspose\BarCode\Model\EncodeBarcodeType::Code128;
My code is code39vin. What i should use instead of Code128 parameter? I find I can use EncodeBarcodeType::VIN, but in response it’s empty array. This is the picture I have a problem with.code1675463252196920156963dd8a54c1757.jpg (3.2 MB)
And I got more one error when upload to production server: “PHP Fatal error: Uncaught Error: Class ‘Aspose\BarCode\Requests\PostBarCodeRecognizeFromUrlorContentRequest’ not found in /home/gsljg68dlt6l/public_html/reporting/recognizePicture.php:59” the code is:
require_once(DIR . ‘/vendor/autoload.php’);

    $config = Aspose\BarCode\Configuration::getDefaultConfiguration();
    $config->setClientId('myID');
    $config->setClientSecret('mySecret');
    $api = new Aspose\BarCode\BarcodeApi(null, $config);
    try {
      $request = new Aspose\BarCode\Requests\PostBarCodeRecognizeFromUrlorContentRequest();
      $request->image = new SplFileObject($fileURL);
      // $request->type = Aspose\BarCode\Model\EncodeBarcodeType::VIN;
      $request->preset = Aspose\BarCode\Model\PresetType::HighPerformance;
On dev server I have no errors.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): BARCODECLOUD-384

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The picture provided is very large (about 8 megapixels) and contains noise from the monitor screen, which makes it difficult to recognize. When the recognition process does not fit within the allotted time, the web server issues a 502 error.

Ways to solve the problem:

  1. Reduce the size of the image (even 20% of the original will be enough)
  2. Use the flag allow_decreased_image = true, then the server will try to recognize the reduced image

Below is the code that recognizes the image in about 15 seconds:

$request = new Aspose\BarCode\Requests\PostBarCodeRecognizeFromUrlorContentRequest();
$request->image = new SplFileObject('code1675463252196920156963dd8a54c1757.jpg');
$request->preset = Aspose\BarCode\Model\PresetType::HighPerformance;
$request->type = Aspose\BarCode\Model\DecodeBarcodeType::VIN;
$request->checksum_validation = Aspose\BarCode\Model\ChecksumValidation::On;

$request->allow_decreased_image = true;

$result = $api->PostBarCodeRecognizeFromUrlorContent($request);
print_r($result);

Hope this helps

Thanks a lot! And what about the error that I wrote about above? “PHP Fatal error: Uncaught Error: Class ‘Aspose\BarCode\Requests\PostBarCodeRecognizeFromUrlorContentRequest’ not found in /home/gsljg68dlt6l/public_html/reporting/recognizePicture.php:59”

Could you please try to run this example:

It’s about barcode generation, and you can change it for your purposes