Skip to main content

UC-021 — Upload and Manage Media

Goal
Upload, list and remove media files from the library
Channel
RCS, WhatsApp
Estimated time
10 minutes

Real-world scenarios​

  • Upload an image for a template: FashionOutlet uploads the image of the new collection to use it as the header of a WhatsApp template.
  • Manage media library: The TravelDream marketing team organizes its library of promotional images, checking which are still in use.
  • Delete obsolete media: At the end of a campaign, the team removes seasonal images to keep the library tidy.

Media management flow​

The diagram shows the media file lifecycle: upload, listing and removal.

Prerequisites​

  • Active API Key with media management permissions
  • The file to upload: any type is accepted, as long as the whole request stays within 10240 KiB (about 10 MB)
  • For RCS: recommended dimensions 1440x1440 px (square images) or 1440x720 px (landscape)

Step 1 — Upload a media file​

Send the file via multipart form-data, in the file part. name, description and folderId are optional: without folderId, or with -1, the media goes in the root of your library.

curl -X POST https://api.qlara.ai/api/partner-gateway/media \
-H "X-Api-Key: YOUR_API_KEY" \
-F "file=@/path/to/promo-estate-2026.jpg" \
-F "name=promo-estate-2026" \
-F "description=Banner promozione estate 2026 - Collezione mare"

Response — Media uploaded​

The response is an array with the created media:

[
{
"id": 5821,
"key": "5b0e72c4/3f9a1d7e6c2b48a59e0d1f7c8b6a4e21.jpg",
"thumbnailKey": "5b0e72c4/a7c4e19b2d5f40c3961e8b0d2f4a6c13.webp",
"companyId": 1287,
"userId": 3410,
"name": "promo-estate-2026",
"description": "Banner promozione estate 2026 - Collezione mare",
"filename": "promo-estate-2026.jpg",
"size": 245760,
"type": "IMAGE",
"mimeType": "image/jpeg",
"source": 1,
"metadata": null,
"folderId": null,
"userEmail": null,
"userFirstName": null,
"userMiddleName": null,
"userLastName": null,
"url": "https://storage.example.com/5b0e72c4/3f9a1d7e6c2b48a59e0d1f7c8b6a4e21.jpg?X-Amz-Date=20260409T090000Z&X-Amz-Expires=3600&X-Amz-Signature=2bbf02e2c8274379a166bb6eb376bcbdb161455399b552eabd3c566b31777738",
"thumbnailUrl": "https://storage.example.com/5b0e72c4/a7c4e19b2d5f40c3961e8b0d2f4a6c13.webp?X-Amz-Date=20260409T090000Z&X-Amz-Expires=3600&X-Amz-Signature=e9c171c6c46a3a250b4e2ba18f76cb7950e31017e7d87092c7cde91d4540d08b",
"cdnUrl": null,
"cdnThumbnailUrl": null,
"public": false,
"creationDate": "2026-04-09 09:00:00.000+0000",
"lastUpdateDate": "2026-04-09 09:00:00.000+0000"
}
]
Use the media by its id

Save the id of the media: a WhatsApp template takes it as its header in headerMediaGalleryId (see UC-006), and an inbox reply attaches it as mediaId (see UC-015). The url field is a signed link to the file: don't save it in your CMS, because it expires. When you need the link again, take the url of the same media from GET /media, which signs a new one at every call.

Behind the scenes — File processing
  1. Type detection: The type (IMAGE, VIDEO, AUDIO, DOCUMENT or FILE) is detected from the file content, and no file type is refused. The upload does not check whether a channel can deliver the file: each channel's own format and size limits apply when you send it.
  2. Optimization: Images wider than 2560 or taller than 1440 px are scaled down to fit, keeping their aspect ratio, and re-encoded as JPEG: they lose any transparency and animation, while filename and mimeType keep the original type. Smaller images and all other files are stored as uploaded, with no resolution check and no conversion per channel.
  3. Storage: The file is saved in the media storage under key and counts against the media storage of your subscription plan. Files uploaded through the API are private: url and thumbnailUrl are signed links that expire, and cdnUrl stays null.
  4. Thumbnail: Images get a WebP thumbnail within 800x800 px, videos a JPEG frame; audio, documents and other files get none.
  5. No malware scan: The file is stored as it is, without being scanned for malicious content.

Step 2 — List uploaded media​

Retrieve the list of files in your media library. The list is paginated (page, limit, 10 items by default) and sorted by id in ascending order, unless you pass sortBy and sortOrder.

curl -X GET https://api.qlara.ai/api/partner-gateway/media \
-H "X-Api-Key: YOUR_API_KEY"

Response — Media list​

{
"data": [
{
"id": 5478,
"key": "5b0e72c4/c2e8f05a7d3b41f69a8e0c5d7b2f9e14.png",
"thumbnailKey": "5b0e72c4/e91b4d7c0a3f42e8b6d5c1a9f0e7d3b2.webp",
"companyId": 1287,
"userId": 3410,
"name": "logo-brand-2026",
"description": null,
"filename": "logo-brand-2026.png",
"size": 52480,
"type": "IMAGE",
"mimeType": "image/png",
"source": 1,
"metadata": null,
"folderId": 214,
"userEmail": "chiara.verdi@example.it",
"userFirstName": "Chiara",
"userMiddleName": null,
"userLastName": "Verdi",
"url": "https://storage.example.com/5b0e72c4/c2e8f05a7d3b41f69a8e0c5d7b2f9e14.png?X-Amz-Date=20260409T093000Z&X-Amz-Expires=3600&X-Amz-Signature=6a23f4aaac740c71ca1c46aff614fe18db294e3fbbf2358db3a5a2c71d9ed24c",
"thumbnailUrl": "https://storage.example.com/5b0e72c4/e91b4d7c0a3f42e8b6d5c1a9f0e7d3b2.webp?X-Amz-Date=20260409T093000Z&X-Amz-Expires=3600&X-Amz-Signature=ab09a190584dbfe3036f6817bab4c3ee15b5b5c3d878e63ddea5ab3098700ed6",
"cdnUrl": null,
"cdnThumbnailUrl": null,
"public": false,
"creationDate": "2026-03-15 08:30:00.000+0000",
"lastUpdateDate": "2026-03-15 08:30:00.000+0000"
},
{
"id": 5821,
"key": "5b0e72c4/3f9a1d7e6c2b48a59e0d1f7c8b6a4e21.jpg",
"thumbnailKey": "5b0e72c4/a7c4e19b2d5f40c3961e8b0d2f4a6c13.webp",
"companyId": 1287,
"userId": 3410,
"name": "promo-estate-2026",
"description": "Banner promozione estate 2026 - Collezione mare",
"filename": "promo-estate-2026.jpg",
"size": 245760,
"type": "IMAGE",
"mimeType": "image/jpeg",
"source": 1,
"metadata": null,
"folderId": null,
"userEmail": "chiara.verdi@example.it",
"userFirstName": "Chiara",
"userMiddleName": null,
"userLastName": "Verdi",
"url": "https://storage.example.com/5b0e72c4/3f9a1d7e6c2b48a59e0d1f7c8b6a4e21.jpg?X-Amz-Date=20260409T093000Z&X-Amz-Expires=3600&X-Amz-Signature=a475228f13f075b0f51ce1615bc4eb5c3b8a46eb56551701cc70d82af0e15898",
"thumbnailUrl": "https://storage.example.com/5b0e72c4/a7c4e19b2d5f40c3961e8b0d2f4a6c13.webp?X-Amz-Date=20260409T093000Z&X-Amz-Expires=3600&X-Amz-Signature=a3ac2131d57c6d2fcc79029fe246d9604f13e35c13711a19bcf689bc5f856c5e",
"cdnUrl": null,
"cdnThumbnailUrl": null,
"public": false,
"creationDate": "2026-04-09 09:00:00.000+0000",
"lastUpdateDate": "2026-04-09 09:00:00.000+0000"
}
],
"page": 0,
"limit": 10,
"totalCount": 2,
"totalPages": 1
}

Step 3 — Delete obsolete media​

Remove a file from the library when it is no longer needed, using its id.

curl -X DELETE https://api.qlara.ai/api/partner-gateway/media/5478 \
-H "X-Api-Key: YOUR_API_KEY"

Response — Media deleted​

The API answers 204 No Content, with an empty body.

Behind the scenes — Deletion
  1. Permanent deletion: The file is removed from the library and from the media storage. The operation cannot be undone.
  2. Messages already sent: They are not affected, because the media content was delivered at send time.
  3. Future references: Any message or campaign that still references the deleted media will fail to resolve the file. Before deleting, make sure it is not used by a scheduled campaign or by a template that has not been sent yet.
  4. Refused deletions: 404 if the id is not in your library, 409 if the media is public or still used by a social media post, 400 if the file is still being uploaded or sits in a read-only folder.

Expected result​

StepActionResult
1POST /mediaFile uploaded, id, key and url returned
2GET /mediaPaginated media list with metadata
3DELETE /media/{id}Media removed, 204 No Content

Complete end-to-end example​

Scenario FashionOutlet: upload an image and use it as the header of a WhatsApp template.

# 1. Upload the promotional image and keep its id
MEDIA_ID=$(curl -s -X POST https://api.qlara.ai/api/partner-gateway/media \
-H "X-Api-Key: YOUR_API_KEY" \
-F "file=@./summer-collection.jpg" \
-F "name=summer-collection-2026" | jq -r '.[0].id')

echo "Media ID: $MEDIA_ID"

# 2. Verify it is in the library (newest first)
curl -s -X GET "https://api.qlara.ai/api/partner-gateway/media?sortBy=id&sortOrder=desc" \
-H "X-Api-Key: YOUR_API_KEY" | jq '.data[] | select(.name == "summer-collection-2026")'

# 3. Use the id as the header of a WhatsApp template (see UC-006)
echo "Ready as template header: headerMediaGalleryId=$MEDIA_ID"

Variants​

Upload a video​

For channels that support video (RCS), upload MP4 files; the request limit of about 10 MB applies as for any other file:

curl -X POST https://api.qlara.ai/api/partner-gateway/media \
-H "X-Api-Key: YOUR_API_KEY" \
-F "file=@/path/to/promo-video.mp4" \
-F "name=promo-video-estate" \
-F "description=Video promozionale 15 secondi"

Common errors​

413 Payload Too Large — Request too large​

The whole request, the file together with the other form fields, may be at most 10240 KiB (10,485,760 bytes). A larger request is refused with 413 before it reaches the API: the response has an empty body, not a JSON one, and the connection is closed.

Solution: Compress the file or reduce its resolution. Images larger than 2560x1440 px are scaled down after the upload anyway, and for RCS Rich Cards 1440px width is sufficient.

429 Too Many Requests — Media storage full​

{
"status": "fail",
"data": "Client error."
}

The file would take your company past the media storage of its subscription plan.

Solution: Delete the media you no longer need with DELETE /media/{id}, or move to a plan with more media storage.

400 Bad Request and 404 Not Found — File or folder​

  • 400 if the file part is missing or the file is empty, and 400 with "data": "Folder is read-only" if folderId names a read-only folder.
  • 404 with "data": "Folder not found" if folderId does not name one of your folders, and 404 if your company has no active subscription.

Solution: Send a non-empty file in the file part, and take folderId from a folder of your library that is not read-only, or leave it out to upload to the root.

Next steps​

References​