How to Scan and Recognize an Image of a Barcode with JavaScript

Cloudmersive
2 min readMay 23, 2022

Since most smartphone cameras can now function as scanners, it’s easier than ever to utilize barcodes. However, you’ll still need an API to lookup scanned barcode images — and that’s where we come in. Our Barcode Scanning API supports dozens of the most used barcodes globally, quickly returning key information about a given product in raw text format. The best part is it’s super easy to use; with code examples provided below, you can easily structure your API call with JavaScript, or you can check out our API console page to find similar documented code examples available in a variety of other common programming languages.

Let’s begin by running the below command to install jQuery:

bower install jquery

After that, let’s include code to capture our Barcode Image and call the Barcode Scanning API:

var form = new FormData();
form.append("imageFile", fileInput.files[0], "file");
var settings = {
"url": "https://api.cloudmersive.com/barcode/scan/image",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});

Once you include your Cloudmersive API key (attainable by creating a free account on our website), you’re all done — the power to scan barcodes is now at your fingertips.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.