POST /api/v1/assets/upload • HTTP 201 Created
Multipart Form-Data File Upload API Example — Request & Response Example
Shows how web applications transmit binary files, avatars, or PDFs to a server alongside text metadata fields using boundary strings.
1. HTTP Client Request (POST)
POST /api/v1/assets/upload HTTP/1.1
{
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
}
{
"file": "[Binary File Buffer: avatar.png, 48.2 KB]",
"folder_name": "avatars",
"is_public": "true"
}
2. Server JSON Response (HTTP 201 Created)
{
"asset_id": "ast_9941a8",
"file_name": "avatar.png",
"file_size_bytes": 49356,
"mime_type": "image/png",
"cdn_url": "https://cdn.cometflow.space/uploads/avatars/avatar_ast_9941a8.png",
"uploaded_at": "2026-10-06T13:00:00Z"
}
Copy-Paste Code Snippets (cURL, JavaScript Fetch, Python, Node.js)
curl -X POST "https://cometflow.space/api/v1/assets/upload" \
-F "file=@/path/to/avatar.png" \
-F "folder_name=avatars"
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('folder_name', 'avatars');
fetch('https://cometflow.space/api/v1/assets/upload', {
method: 'POST',
body: formData
}).then(res => res.json()).then(console.log);
import requests
files = {'file': open('avatar.png', 'rb')}
data = {'folder_name': 'avatars'}
res = requests.post('https://cometflow.space/api/v1/assets/upload', files=files, data=data)
print(res.json()['cdn_url'])
How This API Call Works Step-by-Step
- 1. Browser FormData object bundles binary blob and text metadata.
- 2. Browser automatically calculates multipart boundary delimiters.
- 3. Server streams incoming chunks directly to cloud storage (S3/Cloud Storage).
- 4. Server responds with 201 Created and permanent public CDN link.
Backend API Functions: A middleware such as Multer or Busboy streams multipart chunks, verifies MIME types and byte sizes, and writes the asset to destination storage.
Frequently Asked Questions
Why should you NOT manually set Content-Type for FormData in fetch()?
When using fetch() with a FormData instance, the browser must automatically generate the unique boundary string parameter in the Content-Type header. If you manually set Content-Type: multipart/form-data, the boundary parameter is omitted and the server will fail to parse the upload.