Every product in the store has up to four purpose-built image variants — a full-size principal photo, a thumbnail, a high-resolution zoom, and a square catalog crop. Rather than serving one large original everywhere, the API generates all four sizes at upload time using Sharp, converts them to space-efficient WebP at quality 70, and stores the results in Google Cloud Storage. MongoDB only ever holds the resulting public URLs, keeping your database lean and your images edge-cached.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/Ecommerce/llms.txt
Use this file to discover all available pages before exploring further.
Upload pipeline
Client sends multipart/form-data
The client submits a
POST request with product fields and image files as a multipart/form-data body. Each image is sent under one of four named fields (see Multer fields below).Multer saves files locally
The
multer middleware intercepts the upload and writes each file to storage/product/ on the server’s local filesystem. Files are held here temporarily while processing occurs.imageGenerate runs Sharp
The
imageGenerate function in src/middleware/tools/process.js reads each locally saved file and uses Sharp to produce four resized WebP variants — one per image role. All variants are generated from the same source file in a single pass.Variants uploaded to Google Cloud Storage
Each processed buffer is uploaded to the GCS bucket named by the
NAMEGOOGLECLOUD environment variable. The destination filename follows the pattern {datename}{suffix}_{baseName}.webp, where datename is a date-derived string prefix and suffix is one of ip, mn, idz, or ic.Local file deleted
Once all four GCS uploads succeed, the temporary local file in
storage/product/ is removed to keep disk usage in check.The four image variants
Each uploaded image produces four independently sized outputs. All outputs are WebP at quality 70, regardless of the source format.| Variant | Product field | Dimensions | Aspect ratio | Intended use |
|---|---|---|---|---|
ip — Principal | imageUrlIp | 1500 × 2000 px | 3:4 | Primary product photo on listing and detail pages |
mn — Thumbnail | imageUrlMn | 500 × 666 px | 3:4 | Search results, carousels, compact grids |
idz — Detail/zoom | imageUrlIdz | 2000 × 2667 px | 3:4 | High-resolution zoom viewer on the product detail page |
ic — Square catalog | imageUrlIc | 1080 × 1080 px | 1:1 | Square catalog grids and social-media sharing cards |
Sharp’s
.resize() is called with { fit: 'cover' } semantics, so the source image is cropped to fill the target canvas exactly. Ensure your source photos are at least 2000 px on their shortest side to avoid upscaling artefacts.Multer upload fields
Product create and update endpoints accept exactly four named file fields via multer. Send each image under its corresponding field name.| Field name | Image role | Description |
|---|---|---|
imageUrlIp | Principal | Main portrait photo, 3:4 |
imageUrlMn | Thumbnail | Small portrait, 3:4 |
imageUrlIdz | Detail/zoom | Large portrait for zoom, 3:4 |
imageUrlIc | Square catalog | Square crop, 1:1 |
Image format and quality
All variants are always written as WebP regardless of the source image format (JPEG, PNG, etc.). The WebP encoder is called withquality: 70, which strikes a balance between file size and visual fidelity suitable for e-commerce product photography.
| Setting | Value |
|---|---|
| Output format | WebP |
| Quality | 70 |
| Source formats accepted | Any format supported by Sharp (JPEG, PNG, TIFF, GIF, …) |
GCS URL pattern
Every uploaded variant gets a unique public URL in this form:Image object structure in MongoDB
After processing,imageGenerate returns one object per processed image. That object is stored inside the product’s image array fields:
Unique identifier for this image object, generated by MongoDB.
Public GCS URL for the principal image (1500×2000 px WebP).
Public GCS URL for the thumbnail image (500×666 px WebP).
Public GCS URL for the detail/zoom image (2000×2667 px WebP).
Public GCS URL for the square catalog image (1080×1080 px WebP).
The public GCS URL of the principal (
ip) variant, keyed by the multer field name (e.g., imageUrlIp). Mirrors the value of urlip and is used internally to trace which upload slot produced this object.Environment variables
The GCS bucket name is read from the
NAMEGOOGLECLOUD environment variable at runtime. Make sure this variable is set in your .env file (or your deployment environment) before starting the server — missing it will cause all image uploads to fail.Example: creating a product with images
The followingcurl command creates a new product and uploads all four image variants in a single multipart request.
imageUrl* arrays populated with GCS objects: