Image Attach Plugin: How to upload 100,000 photos the right way
Folder structure, patterns, WebP, lazy load, CDN. The complete working flow with code examples.
Published 2026-09-14 • Category: Plugins • Reading time: 10 min
The task
Electronics store. 100,000 products, each with 1 to 8 photos. Total ~430,000 files at 180 GB. We need to load them into Magento, attach to the right products, generate WebP copies and push to a CDN.
Folder structure
The pattern we’ve used for years:
/media/import/
SKU-00001/
main.jpg
gallery_1.jpg
gallery_2.jpg
gallery_3.jpg
SKU-00002/
main.jpg
...
Image Attach Plugin pulls photos via the SKU/filename pattern; main.jpg becomes base + small + thumbnail, gallery_* goes into the gallery.
Image Attach configuration
; In magmi.ini
IMAGEATTACH_ROOT = "/var/www/magento/media/import/"
IMAGEATTACH_PATTERN = "{sku}/{filename}"
In the CSV, the image, small_image, thumbnail and media_gallery columns contain just file names (main.jpg, gallery_1.jpg).
WebP conversion
Magento 2 supports WebP natively from 2.4.6+. For older versions — the Yireo_Webp2 module. We run WebP conversion as a post-import script:
find /var/www/magento/pub/media/catalog/product/ \
-name "*.jpg" -exec cwebp -q 80 {} -o {}.webp \;
Lazy load
Hyva Theme and newer Luma-based themes ship with lazy load. If your theme is older, add loading="lazy" in product listings via XML layout or an overridden template.
CDN
Point BunnyCDN or Cloudflare at /pub/media/*. Pull-based CDN handles image optimisation on the fly. For images it is always cheaper than self-hosting.
Monitoring
After import, always compare the DB media count against the files on disk:
SELECT COUNT(*) FROM catalog_product_entity_media_gallery;
# vs
find /var/www/magento/pub/media/catalog/product -type f | wc -l
A gap over 1% means something went wrong — check the Magmi log.
Leave a Reply