ByteScout Cloud API Server - Barcode Reader API - Python - Read Barcode From Uploaded File - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout Cloud API Server – Barcode Reader API – Python – Read Barcode From Uploaded File

  • Home
  • /
  • Articles
  • /
  • ByteScout Cloud API Server – Barcode Reader API – Python – Read Barcode From Uploaded File

How to read barcode from uploaded file for barcode reader API in Python using ByteScout Cloud API Server

How to read barcode from uploaded file in Python with easy ByteScout code samples to make barcode reader API. Step-by-step tutorial

Every ByteScout tool includes sample Python source codes that you can find here or in the folder with installed ByteScout product. ByteScout Cloud API Server was designed to assist barcode reader API in Python. ByteScout Cloud API Server is API server that is ready to use and can be installed and deployed in less than 30 minutes on your own Windows server or server in a cloud. It can save data and files on your local server-based file storage or in Amazon AWS S3 storage. Data is processed solely on the API server and is powered by ByteScout engine, no cloud services or Internet connection is required for data processing..

If you want to speed up the application’s code writing then Python code samples for Python developers help to implement using ByteScout Cloud API Server. Follow the tutorial and copy – paste code for Python into your project’s code editor. Enjoy writing a code with ready-to-use sample Python codes to add barcode reader API functions using ByteScout Cloud API Server in Python.

Trial version of ByteScout is available for free download from our website. This and other source code samples for Python and other programming languages are available.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

ReadBarcodeFromUploadedFile.py
      
import os import requests # pip install requests # Please NOTE: In this sample we're assuming Cloud Api Server is hosted at "https://localhost". # If it's not then please replace this with with your hosting url. # Base URL for PDF.co Web API requests BASE_URL = "https://localhost" # Source file name SourceFile = ".\\sample.pdf" # Comma-separated list of barcode types to search. # See valid barcode types in the documentation https://app.pdf.co/documentation/api/1.0/barcode/read_from_url.html BarcodeTypes = "Code128,Code39,Interleaved2of5,EAN13" # Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'. Pages = "" def main(args = None): uploadedFileUrl = uploadFile(SourceFile) if (uploadedFileUrl != None): readBarcodes(uploadedFileUrl) def readBarcodes(uploadedFileUrl): """Get Barcode Information using PDF.co Web API""" # Prepare URL for 'Barcode Reader' API request url = "{}/barcode/read/from/url?types={}&pages={}&url={}".format( BASE_URL, BarcodeTypes, Pages, uploadedFileUrl ) # Execute request and get response as JSON response = requests.get(url, headers={ "content-type": "application/octet-stream" }) if (response.status_code == 200): json = response.json() if json["error"] == False: # Display information for barcode in json["barcodes"]: print("Found barcode:") print(f" Type: {barcode['TypeName']}") print(f" Value: {barcode['Value']}") print(f" Document Page Index: {barcode['Page']}") print(f" Rectangle: {barcode['Rect']}") print(f" Confidence: {barcode['Confidence']}") print("") else: # Show service reported error print(json["message"]) else: print(f"Request error: {response.status_code} {response.reason}") def uploadFile(fileName): """Uploads file to the cloud""" # 1. RETRIEVE PRESIGNED URL TO UPLOAD FILE. # Prepare URL for 'Get Presigned URL' API request url = "{}/file/upload/get-presigned-url?contenttype=application/octet-stream&name={}".format( BASE_URL, os.path.basename(fileName)) # Execute request and get response as JSON response = requests.get(url) if (response.status_code == 200): json = response.json() if json["error"] == False: # URL to use for file upload uploadUrl = json["presignedUrl"] # URL for future reference uploadedFileUrl = json["url"] # 2. UPLOAD FILE TO CLOUD. with open(fileName, 'rb') as file: requests.put(uploadUrl, data=file, headers={ "content-type": "application/octet-stream" }) return uploadedFileUrl else: # Show service reported error print(json["message"]) else: print(f"Request error: {response.status_code} {response.reason}") return None if __name__ == '__main__': main()

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next