The Bags API supports file uploads for token creation with specific requirements and formats.

Upload Requirements

  • Maximum file size: 15MB for image uploads
  • Content-Type: multipart/form-data for file upload endpoints
  • File field name: image (required field name for all image uploads)
  • Supported formats: PNG, JPG, JPEG, GIF, WebP

Basic File Upload

Single Image Upload

curl -X POST 'https://public-api-v2.bags.fm/api/v1/token-launch/create-launch-transaction' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'Content-Type: multipart/form-data' \
  -F 'image=@/path/to/your/image.png' \
  -F 'name=My Token' \
  -F 'symbol=MYTOKEN'

Advanced Upload Examples

Validate File Before Upload

function validateImageFile(file) {
  // Check file size (15MB = 15 * 1024 * 1024 bytes)
  const maxSize = 15 * 1024 * 1024;
  if (file.size > maxSize) {
    throw new Error('File size must be under 15MB');
  }
  
  // Check file type
  const allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif', 'image/webp'];
  if (!allowedTypes.includes(file.type)) {
    throw new Error('File must be PNG, JPG, JPEG, GIF, or WebP');
  }
  
  return true;
}

// Usage
try {
  validateImageFile(fileInput.files[0]);
  // Proceed with upload
} catch (error) {
  console.error('Validation error:', error.message);
}

Error Handling

Common Upload Errors

File too large (413):
{
  "success": false,
  "error": "Image file must be under 15MB"
}
Invalid file type (400):
{
  "success": false,
  "error": "Unsupported file type. Please upload PNG, JPG, JPEG, GIF, or WebP images."
}
Missing file (400):
{
  "success": false,
  "error": "Image file is required"
}
Corrupted file (400):
{
  "success": false,
  "error": "Invalid image file. Please check your file and try again."
}

Best Practices

  1. Always validate files client-side before uploading to save bandwidth and API quota
  2. Compress images when possible to improve upload speed and user experience
  3. Show progress indicators for better user experience during uploads
  4. Handle network interruptions with retry logic for failed uploads
  5. Use appropriate image formats - PNG for graphics with transparency, JPEG for photos
  6. Optimize image dimensions - resize to appropriate dimensions before upload
Uploaded images are processed and optimized by the Bags system. The final image URL may differ from your uploaded version.
Consider implementing client-side image compression to improve upload speeds and stay within file size limits.