{
  "productId": "550e8400-e29b-41d4-a716-446655440000",
  "uploadedImages": [
    {
      "originalName": "product-main.jpg",
      "url": "https://devdraft-images.s3.amazonaws.com/products/550e8400/main-1642671234567.jpg",
      "thumbnailUrl": "https://devdraft-images.s3.amazonaws.com/products/550e8400/thumb-main-1642671234567.jpg",
      "size": 2547680,
      "dimensions": {
        "width": 1200,
        "height": 1200
      },
      "position": 0,
      "uploadedAt": "2024-01-21T10:30:00.000Z"
    },
    {
      "originalName": "product-detail.jpg",
      "url": "https://devdraft-images.s3.amazonaws.com/products/550e8400/detail-1642671234890.jpg",
      "thumbnailUrl": "https://devdraft-images.s3.amazonaws.com/products/550e8400/thumb-detail-1642671234890.jpg",
      "size": 1876543,
      "dimensions": {
        "width": 1000,
        "height": 800
      },
      "position": 1,
      "uploadedAt": "2024-01-21T10:30:01.000Z"
    }
  ],
  "totalImages": 2,
  "processing": {
    "status": "completed",
    "optimizationApplied": true,
    "thumbnailsGenerated": true,
    "cdnDistributed": true
  },
  "updatedProduct": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "Premium Software License",
    "images": [
      "https://devdraft-images.s3.amazonaws.com/products/550e8400/main-1642671234567.jpg",
      "https://devdraft-images.s3.amazonaws.com/products/550e8400/detail-1642671234890.jpg"
    ],
    "imageCount": 2,
    "lastImageUpdate": "2024-01-21T10:30:01.000Z"
  }
}
The Upload Product Images endpoint allows you to add, replace, or manage images for existing products. Images are automatically optimized, resized for different use cases, and served via CDN for fast loading. This endpoint supports multiple image formats and provides comprehensive image management capabilities.

Endpoint Details

method
string
POST
url
string
/api/v0/products/{id}/images
content-type
string
multipart/form-data
Authentication: Required (API Key & Secret)
Idempotency: Supported (recommended for upload operations)

Parameters

id
string
required
Product ID to upload images for
Format: UUID v4
Example: "550e8400-e29b-41d4-a716-446655440000"

Form Data Fields

images
file[]
required
Image files to upload (multiple files supported)
Max files: 10 per request
Max size: 10MB per file
replaceAll
boolean
Whether to replace all existing images
Default: false
Example: true
position
integer
Starting position for new images (0-based)
Default: Append to end
Example: 2

Image Requirements

Supported Formats

  • JPEG (.jpg, .jpeg)
  • PNG (.png)
  • WebP (.webp)
  • GIF (.gif) - animations preserved

Size Specifications

  • Maximum file size: 10MB per image
  • Recommended dimensions: 1200x1200px or larger
  • Minimum dimensions: 400x400px
  • Aspect ratio: Square (1:1) recommended for best display

Quality Guidelines

  • Resolution: High-resolution images for best quality
  • Compression: Balanced compression for web optimization
  • Background: Clean, professional backgrounds preferred
  • Lighting: Even lighting with minimal shadows

Request Examples

curl -X POST "https://api.devdraft.ai/api/v0/products/550e8400-e29b-41d4-a716-446655440000/images" \
  -H "x-client-key: YOUR_CLIENT_KEY" \
  -H "x-client-secret: YOUR_CLIENT_SECRET" \
  -H "x-idempotency-key: $(uuidgen)" \
  -F "images=@/path/to/product-image.jpg"

Response Format

Success Response (200 OK)

{
  "productId": "550e8400-e29b-41d4-a716-446655440000",
  "uploadedImages": [
    {
      "originalName": "product-main.jpg",
      "url": "https://devdraft-images.s3.amazonaws.com/products/550e8400/main-1642671234567.jpg",
      "thumbnailUrl": "https://devdraft-images.s3.amazonaws.com/products/550e8400/thumb-main-1642671234567.jpg",
      "size": 2547680,
      "dimensions": {
        "width": 1200,
        "height": 1200
      },
      "position": 0,
      "uploadedAt": "2024-01-21T10:30:00.000Z"
    },
    {
      "originalName": "product-detail.jpg",
      "url": "https://devdraft-images.s3.amazonaws.com/products/550e8400/detail-1642671234890.jpg",
      "thumbnailUrl": "https://devdraft-images.s3.amazonaws.com/products/550e8400/thumb-detail-1642671234890.jpg",
      "size": 1876543,
      "dimensions": {
        "width": 1000,
        "height": 800
      },
      "position": 1,
      "uploadedAt": "2024-01-21T10:30:01.000Z"
    }
  ],
  "totalImages": 2,
  "processing": {
    "status": "completed",
    "optimizationApplied": true,
    "thumbnailsGenerated": true,
    "cdnDistributed": true
  },
  "updatedProduct": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "Premium Software License",
    "images": [
      "https://devdraft-images.s3.amazonaws.com/products/550e8400/main-1642671234567.jpg",
      "https://devdraft-images.s3.amazonaws.com/products/550e8400/detail-1642671234890.jpg"
    ],
    "imageCount": 2,
    "lastImageUpdate": "2024-01-21T10:30:01.000Z"
  }
}

Error Responses

{
  "statusCode": 400,
  "message": "Invalid image upload request",
  "error": "Bad Request",
  "details": {
    "invalidFiles": [
      {
        "filename": "invalid.txt",
        "reason": "Unsupported file type"
      },
      {
        "filename": "too-large.jpg",
        "reason": "File size exceeds 10MB limit"
      }
    ],
    "validFiles": 2,
    "totalFiles": 4
  }
}

Image Processing

Automatic Optimization

  • Format Conversion: WebP generation for modern browsers
  • Size Optimization: Multiple sizes for different use cases
  • Quality Adjustment: Balanced compression for web delivery
  • Thumbnail Generation: Small previews for listings

Generated Variants

  • Original: Uploaded image (up to 10MB)
  • Large: 1200px max dimension for product pages
  • Medium: 600px max dimension for catalogs
  • Small: 300px max dimension for thumbnails
  • WebP: Modern format for supported browsers

CDN Distribution

  • Global Delivery: Images served from edge locations
  • Cache Headers: Optimized caching for fast loading
  • SSL/HTTPS: Secure image delivery
  • Responsive URLs: Different sizes for different devices

Best Practices

Image Organization

// Organize images by purpose
const imageStrategy = {
  primary: 'main-product-shot.jpg',        // Hero image
  details: 'product-details.jpg',          // Close-up features
  lifestyle: 'product-in-use.jpg',         // Usage context
  packaging: 'product-packaging.jpg',      // Box/packaging
  variants: 'product-colors.jpg'           // Different options
};

// Upload in priority order
const priorityOrder = [
  imageStrategy.primary,
  imageStrategy.details,
  imageStrategy.lifestyle,
  imageStrategy.packaging,
  imageStrategy.variants
];

Performance Optimization

// Pre-validate before upload
const validateBeforeUpload = async (files) => {
  const validation = await imageManager.validateImages(files);
  
  if (!validation.allValid) {
    throw new Error(`Invalid files: ${validation.invalidFiles.join(', ')}`);
  }
  
  return validation.validFiles;
};

// Optimize for web
const optimizeForWeb = async (files) => {
  return await Promise.all(
    files.map(file => imageManager.optimizeImageQuality(file, 1200, 0.8))
  );
};

// Progressive upload
const progressiveUpload = async (productId, files) => {
  // Upload primary image first
  await imageManager.uploadImages(productId, [files[0]], { replaceAll: true });
  
  // Upload remaining images in background
  if (files.length > 1) {
    setTimeout(() => {
      imageManager.uploadImages(productId, files.slice(1));
    }, 1000);
  }
};

Quality Guidelines

  • Resolution: Upload high-resolution originals (1200px+ recommended)
  • Aspect Ratio: Square (1:1) or landscape (4:3) work best
  • Background: Clean, neutral backgrounds for product shots
  • Lighting: Even, natural lighting without harsh shadows
  • Focus: Sharp focus on product details
  • Context: Include lifestyle shots showing product in use

Advanced Features

Batch Processing

// Upload with progress tracking
const uploadWithProgress = async (productId, files, onProgress) => {
  const total = files.length;
  let completed = 0;
  
  const batchSize = 3;
  const batches = [];
  
  for (let i = 0; i < files.length; i += batchSize) {
    batches.push(files.slice(i, i + batchSize));
  }
  
  const results = [];
  
  for (const batch of batches) {
    try {
      const result = await imageManager.uploadImages(productId, batch);
      results.push(result);
      completed += batch.length;
      
      onProgress({
        completed,
        total,
        percentage: Math.round((completed / total) * 100),
        currentBatch: results.length,
        totalBatches: batches.length
      });
    } catch (error) {
      results.push({ error: error.message });
    }
  }
  
  return results;
};

Image Management

// Organize product images by category
const organizeProductImages = async (productId, imageCategories) => {
  const uploads = [];
  
  // Upload main images first
  if (imageCategories.main) {
    uploads.push(
      imageManager.uploadImages(productId, imageCategories.main, { 
        replaceAll: true,
        position: 0 
      })
    );
  }
  
  // Add detail images
  if (imageCategories.details) {
    uploads.push(
      imageManager.uploadImages(productId, imageCategories.details, { 
        position: imageCategories.main?.length || 0 
      })
    );
  }
  
  // Add lifestyle images
  if (imageCategories.lifestyle) {
    uploads.push(
      imageManager.uploadImages(productId, imageCategories.lifestyle, { 
        position: (imageCategories.main?.length || 0) + (imageCategories.details?.length || 0)
      })
    );
  }
  
  return await Promise.all(uploads);
};

Next Steps

After uploading product images, you can:
  1. Update Product Details: Modify product information to reference new images
  2. Test Display: Verify images appear correctly in your application
  3. Optimize Loading: Implement lazy loading and responsive images
  4. Monitor Performance: Track image load times and conversion impact
  5. Manage Storage: Set up automated cleanup for unused images