The UPC Database API might return images in different formats. Let's check!
Try scanning one of these common barcodes:
Coca-Cola (12-pack): 049000050103
Oreos: 044000032326
Cheerios: 016000275256
Red Bull: 611269991512
- Open the app: https://barcode-scanner-cs465.web.app
- Open browser DevTools (F12 on desktop, or inspect on mobile)
- Go to Console tab
- Scan a barcode
- Look for logs like:
"Found product image: https://...""No product image available"
The UPC Database API response looks like this:
{
"success": true,
"title": "Coca Cola Classic",
"brand": "Coca Cola",
"description": "Carbonated Soft Drink",
"category": "Beverages",
"images": [
"https://images.upcdatabase.org/product/123.jpg"
],
"offers": [],
"// ... more fields"
}Important: Not all products have images! It depends on:
- If someone uploaded a photo
- Product popularity
- Database coverage
Want to test the API directly? Use this:
# Replace YOUR_API_KEY with: 4190D3F1E6057DD921DA7E426A79AAF3
curl "https://api.upcdatabase.org/product/049000050103" \
-H "Authorization: Bearer YOUR_API_KEY"- API doesn't have that image - Most common reason
- Wrong field name - My code checks:
images[0],image_url,image,imageUrl - CORS issues - The proxy should fix this
- Image URL is broken - The image file doesn't exist anymore
My code handles missing images gracefully:
img.onerror = () => {
imgContainer.style.display = 'none'; // Hide if image fails to load
};So if there's no image, you just won't see one - no error!
If you want to ALWAYS show an image, even if the API doesn't have one:
const imageUrl = info.images?.[0] ||
info.image_url ||
info.image ||
'https://via.placeholder.com/300x300?text=No+Image'; // FallbackThis shows a placeholder if no real image exists.
Expected behavior:
- ✅ Popular products (Coca-Cola, Oreos) → Should show images
- ✅ Generic products → Might not have images
- ✅ Random barcodes → Probably no images
Test with:
- Household items with packaging
- Food products from stores
- Popular brands
Don't test with:
- Handmade QR codes (no product data)
- Random numbers (not real barcodes)
- Very obscure products
If the UPC Database doesn't have enough images, you could:
- Add multiple APIs - Check UPC DB first, then try Open Food Facts
- Let users upload - Use Firebase Storage to save custom photos
- Google Image Search - Search for product name + "product image"
Want me to implement any of these? Let me know!