Skip to main content
POST
/
api
/
qr
QR Code Scanning
curl --request POST \
  --url https://api.example.com/api/qr \
  --header 'Content-Type: application/json' \
  --data '{}'
{
  "message": "<string>",
  "data": "<string>",
  "error": "<string>"
}

Endpoint

POST /api/qr
Scans an uploaded image for QR codes and decodes the contained data using OpenCV’s QRCodeDetector.

Authentication

This endpoint requires authentication via Bearer token in the Authorization header.
Authorization: Bearer <your_access_token>

Request

file
file
required
The image file containing a QR code. Supports common image formats (JPG, PNG, etc.)Must be sent as multipart/form-data.
File Format Requirements:
  • Supported formats: JPG, JPEG, PNG, BMP, and other OpenCV-compatible formats
  • QR code should be clearly visible and not distorted
  • Good lighting and contrast improve detection accuracy
  • Image is automatically saved to uploads/ folder with timestamp if filename not provided

Response

message
string
Success message when QR code is detected and decoded
data
string
The decoded data from the QR code (URL, text, or any encoded information)
error
string
Error message if no QR code is found in the image

Success Response (200)

{
  "message": "QR Scanned successfully",
  "data": "https://example.com/product/12345"
}

No QR Code Found (200)

{
  "error": "No QR code found in the image"
}

Error Response (401)

{
  "detail": "Authorization header missing or invalid."
}

Code Examples

curl -X POST https://api.expireeye.com/api/qr \
  -H "Authorization: Bearer your_access_token" \
  -F "file=@/path/to/qr-code.jpg"

Implementation Details

QR Code Detection Process

  1. Image Upload: The image file is received as multipart/form-data
  2. Image Processing:
    • Image bytes are read into a NumPy array
    • OpenCV decodes the image from the byte array
    • Image is saved to the uploads/ folder for processing
  3. QR Detection:
    • OpenCV’s QRCodeDetector() is initialized
    • The detector scans the image using detectAndDecode()
    • Returns decoded data and bounding box coordinates
  4. Response:
    • If QR code found: Returns success message with decoded data
    • If no QR code: Returns error message

Technology Stack

  • OpenCV: Used for image processing and QR code detection
  • NumPy: Array manipulation for image data
  • FastAPI: Request handling and file uploads

File Handling

Images are saved with the following naming convention:
  • If filename provided: Uses original filename
  • If no filename: Generates timestamp-based name (format: qr_YYYYMMDD_HHMMSS.jpg)
Upload directory: uploads/

Detection Capabilities

The OpenCV QRCodeDetector can decode:
  • URLs
  • Plain text
  • Contact information (vCard)
  • WiFi credentials
  • Any UTF-8 encoded data in QR codes

User Context

The endpoint extracts the user ID from the JWT token for potential future features like:
  • Adding scanned products to user inventory (currently commented out)
  • Tracking scan history
  • User-specific analytics
Future Enhancement: The endpoint includes commented code for automatically adding scanned products to the user’s inventory. This feature can be enabled to streamline the product addition workflow.

Error Handling

Status CodeDescription
200Success - QR code decoded or no QR code found
401Unauthorized - Missing or invalid access token
422Validation Error - Invalid file format or missing file
500Internal Server Error - Image processing failure

Build docs developers (and LLMs) love