Start a chunked upload
Open an upload session for a large file and get the chunk size and the number of chunks to send. This page also explains the whole chunked upload flow.
Use a chunked upload for videos and for any file above 64 MB (the largest request the server takes). It also works for smaller files. Videos can be up to 200 MB, images and GIFs up to 15 MB.
How the flow works
- Start. Call this endpoint with the file name, MIME type and size in bytes. The response has an
upload_uuid, thechunk_sizein bytes andtotal_chunks. - Send the chunks. Cut the file into pieces of
chunk_sizebytes (the last piece is shorter) and send each one with Upload a chunk, numbered from0tototal_chunks - 1. Send each chunk once. The order does not matter. - Finish. When every chunk is in, call Complete a chunked upload. SocialKit joins the chunks and returns the media object. A file that is not completed does not appear in the library.
- Or cancel. Cancel a chunked upload throws away the chunks already sent.
A session belongs to the workspace and to the user whose key opened it. Another key gets the same Upload session not found. error as for a session that does not exist.
The chunk size is 10 MB. A file of 10 MB or less is sent as one chunk of its own size, with total_chunks: 1. Always read the size from the response instead of fixing it in your code.
Request
- Method:
POST - URL:
https://app.socialk.it/core/api/<workspaceUuid>/media/chunked/initiate - Authorization:
Bearer <personal-key> - Content-Type:
application/json - Roles: Admin, Member (see Permissions)
Path parameters
| Parameter | Type | Description |
|---|---|---|
workspaceUuid | string | UUID of the workspace. |
Body
{
"filename": "product-demo.mp4",
"mime_type": "video/mp4",
"total_size": 52428800
}| Field | Type | Required | Description |
|---|---|---|---|
filename | string | Yes | Name of the file, up to 255 characters. |
mime_type | string | Yes | MIME type of the file. The allowed types are listed on Upload a media file. |
total_size | integer | Yes | Size of the whole file in bytes, at least 1 and within the limit for its kind (15 MB for images and GIFs, 200 MB for videos). |
Example
The whole flow in a shell, using jq and split:
API='https://app.socialk.it/core/api/<workspaceUuid>'
KEY='<personal-key>'
FILE=product-demo.mp4
# 1. start
SESSION=$(curl -s -X POST "$API/media/chunked/initiate" \
-H 'Accept: application/json' -H "Authorization: Bearer $KEY" \
-H 'Content-Type: application/json' \
-d "{\"filename\": \"$FILE\", \"mime_type\": \"video/mp4\", \"total_size\": $(wc -c < $FILE | tr -d ' ')}")
UPLOAD=$(echo "$SESSION" | jq -r .upload_uuid)
CHUNK=$(echo "$SESSION" | jq -r .chunk_size)
# 2. send the chunks
split -b "$CHUNK" -d -a 4 "$FILE" part_
i=0
for p in part_*; do
curl -s -X POST "$API/media/chunked/$UPLOAD/upload" \
-H 'Accept: application/json' -H "Authorization: Bearer $KEY" \
-F "chunk=@$p" -F "chunk_index=$i"
i=$((i+1))
done
# 3. finish
curl -s -X POST "$API/media/chunked/$UPLOAD/complete" \
-H 'Accept: application/json' -H "Authorization: Bearer $KEY"Response
{
"upload_uuid": "9b4e2d71-5c08-4a3f-8e16-d27f0a6b3c59",
"chunk_size": 10485760,
"total_chunks": 5
}Other 422 errors: The selected mime type is invalid. under mime_type, a missing field, or the plan storage limit described on Upload a media file.