How to upload images and files through the Bags API
multipart/form-data
image
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'
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); }
{ "success": false, "error": "Image file must be under 15MB" }
{ "success": false, "error": "Unsupported file type. Please upload PNG, JPG, JPEG, GIF, or WebP images." }
{ "success": false, "error": "Image file is required" }
{ "success": false, "error": "Invalid image file. Please check your file and try again." }