Skip to content

Guides

Upload media

Upload images and videos with a direct upload URL, then attach them to posts as single media or carousels.

Posts can only attach files you uploaded to Flenvio. Uploading has three steps: ask for an upload URL, send the file there, then ask Flenvio to check it. You get back a url to put in a post’s mediaUrls.

ItemLimit
File typesJPEG, PNG, GIF and WebP images; MP4 and MOV videos
Image sizeUp to 10 MB
Video sizeUp to 1 GB
Uploads per day200 in any 24 hours
Storage10 GB in total, including unfinished uploads
Starting uploads30 per minute

1. Ask for an upload URL

Send the file’s type and exact size in bytes:

curl -X POST "https://api.flenvio.com/v1/media/uploads" \
  -H "x-api-key: $FLENVIO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "contentType": "image/jpeg",
  "sizeBytes": 482113
}'
Response · 201
{
  "assetId": "a55e7000-0000-4000-8000-000000000001",
  "uploadUrl": "https://media.flenvio.example/uploads/5c1f0e2a-0000-4000-8000-000000000001.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&X-Amz-SignedHeaders=content-length%3Bcontent-type%3Bhost&X-Amz-Signature=…",
  "method": "PUT",
  "headers": {
    "Content-Type": "image/jpeg"
  }
}

2. Send the file

PUT the raw bytes to uploadUrl with the headers from the response, and without your API key (the URL carries its own permission). The body must be exactly sizeBytes long. The URL works for one hour.

curl
curl -X PUT "$UPLOAD_URL" \
  -H 'Content-Type: image/jpeg' \
  --data-binary @photo.jpg

3. Complete the upload

Flenvio reads the stored file, checks that it really is the type and size you declared, and records its dimensions and duration. Only completed uploads can be attached to posts.

curl -X POST "https://api.flenvio.com/v1/media/uploads/a55e7000-0000-4000-8000-000000000001/complete" \
  -H "x-api-key: $FLENVIO_API_KEY"
Response · 200
{
  "id": "a55e7000-0000-4000-8000-000000000001",
  "url": "https://media.flenvio.example/uploads/5c1f0e2a-0000-4000-8000-000000000001.jpg",
  "key": "uploads/5c1f0e2a-0000-4000-8000-000000000001.jpg",
  "meta": {
    "kind": "image",
    "width": 1080,
    "height": 1350,
    "format": "jpeg"
  }
}
  • Completing twice is safe: it returns the same result.
  • Completing before the file arrived returns 400 (The file has not been uploaded yet.); send the file, then try again.
  • A file that isn’t what you declared is deleted and returns 400. Start over with the right type and size.
  • Uploads never completed are removed after 6 hours. Completed files that no post uses are removed after 48 hours, so upload shortly before you post. Files attached to a post are kept.

All three steps

import { readFile } from 'node:fs/promises';

const BASE_URL = 'https://api.flenvio.com';
const API_KEY = process.env.FLENVIO_API_KEY;

async function call(path, body) {
  const res = await fetch(BASE_URL + path, {
    method: 'POST',
    headers: body
      ? { 'x-api-key': API_KEY, 'Content-Type': 'application/json' }
      : { 'x-api-key': API_KEY },
    body: body ? JSON.stringify(body) : undefined,
  });
  const data = await res.json();
  if (!res.ok) throw new Error(`${res.status}: ${JSON.stringify(data.message)}`);
  return data;
}

export async function uploadFile(path, contentType) {
  const bytes = await readFile(path);
  // 1. Ask for an upload URL for this exact type and size.
  const upload = await call('/v1/media/uploads', { contentType, sizeBytes: bytes.length });
  // 2. Send the bytes to that URL with exactly the returned headers.
  const put = await fetch(upload.uploadUrl, { method: upload.method, headers: upload.headers, body: bytes });
  if (!put.ok) throw new Error(`Upload failed with ${put.status}`);
  // 3. Ask Flenvio to check the file. The result's url goes in a post.
  return call(`/v1/media/uploads/${upload.assetId}/complete`);
}

const photo = await uploadFile('photo.jpg', 'image/jpeg');
console.log(photo.url, photo.meta);

Small files in one request

Files up to 10 MB can instead be sent as multipart/form-data in a single request. The type is detected from the file itself. It returns the same result as completing an upload.

curl -X POST "https://api.flenvio.com/v1/media/upload" \
  -H "x-api-key: $FLENVIO_API_KEY" \
  -F '[email protected];type=image/jpeg'

Attach media to a post

Put the url values in mediaUrls, in the order they should appear. One item is a single image or video; several make a carousel where the platform supports it.

curl -X POST "https://api.flenvio.com/v1/posts" \
  -H "x-api-key: $FLENVIO_API_KEY" \
  -H 'Idempotency-Key: 6a1f9d52-0000-4000-8000-000000000003' \
  -H 'Content-Type: application/json' \
  -d '{
  "accountIds": [
    "acc1a000-0000-4000-8000-000000000001"
  ],
  "caption": "Two roasts, side by side.",
  "mediaUrls": [
    "https://media.flenvio.example/uploads/5c1f0e2a-0000-4000-8000-000000000001.jpg",
    "https://media.flenvio.example/uploads/5c1f0e2a-0000-4000-8000-000000000002.jpg"
  ]
}'
  • Instagram: up to 10 items; images and videos can be mixed. A single video is published as a Reel.
  • Threads: up to 20 items, mixed allowed.
  • Facebook: several items must all be images; a video goes on its own.
  • YouTube: exactly one video.
  • TikTok: one video, or up to 35 photos.

Upload errors

StatusMessageWhat to do
400Only JPEG, PNG, GIF, WebP, MP4 and MOV files can be uploaded.Convert the file to a supported type.
413Images can be at most 10MB. / Videos can be at most 1024MB.Compress or shorten the file.
400You've reached the limit of 200 uploads per day. Try again tomorrow.Wait, or reuse files you already uploaded.
400This upload would exceed your media storage limit…Unused uploads are cleared after 48 hours.
400This upload expired. Upload the file again.Start a new upload.
400 on POST /v1/postsOne or more media items were not uploaded by you, or have not finished uploading.Use the url from a completed upload, unchanged.
429ThrottlerException: Too Many RequestsMore than 30 uploads started in a minute; wait for Retry-After seconds.
Upload media · Flenvio API · Flenvio