Tải tệp đa phương tiện lên
curl --request POST \
--url https://app.getkavio.app/api/posts/{post}/media \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{}'import requests
url = "https://app.getkavio.app/api/posts/{post}/media"
payload = {}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('https://app.getkavio.app/api/posts/{post}/media', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.getkavio.app/api/posts/{post}/media",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.getkavio.app/api/posts/{post}/media"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://app.getkavio.app/api/posts/{post}/media")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.getkavio.app/api/posts/{post}/media")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"
response = http.request(request)
puts response.read_bodyBài đăng
Tải tệp đa phương tiện lên
Tải ảnh hoặc video từ máy của bạn lên và đính kèm vào bài đăng.
POST
/
posts
/
{post}
/
media
Tải tệp đa phương tiện lên
curl --request POST \
--url https://app.getkavio.app/api/posts/{post}/media \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{}'import requests
url = "https://app.getkavio.app/api/posts/{post}/media"
payload = {}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('https://app.getkavio.app/api/posts/{post}/media', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.getkavio.app/api/posts/{post}/media",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.getkavio.app/api/posts/{post}/media"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://app.getkavio.app/api/posts/{post}/media")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.getkavio.app/api/posts/{post}/media")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"
response = http.request(request)
puts response.read_bodyĐể đính kèm nội dung đa phương tiện từ URL công khai thay vì tải tệp lên, hãy dùng
Các loại nội dung đa phương tiện được hỗ trợ:
POST /posts/{post}/media/from-url.
Tham số đường dẫn
string
bắt buộc
UUID của bài đăng cần đính kèm tệp.
Yêu cầu
Gửi dưới dạngmultipart/form-data với một trường media.
file
bắt buộc
Tệp cần tải lên, thuộc một trong các loại được phép:
- Ảnh:
image/jpeg,image/png,image/gif,image/webp- up to 10 MB - Video:
video/mp4,video/quicktime(MOV) - up to 1 GB
Cách hoạt động
- Bài đăng phải thuộc không gian làm việc hiện tại của bên gọi; nếu không, API trả về
404. - Loại MIME của tệp phải được nền tảng đang bật trong bài đăng hỗ trợ. Ví dụ, tải ảnh lên bài chỉ dùng TikTok sẽ trả về
422, trừ khi bài dùngtiktok_photo. - Giới hạn dung lượng theo từng loại được áp dụng sau khi phát hiện MIME. Video lớn hơn 1 GB trả về
422, kể cả khi giới hạn chung của yêu cầu cho phép. - Ảnh tĩnh PNG và WebP được chuẩn hóa thành JPEG (q100) khi lưu để tương thích với mọi nền tảng. GIF được giữ nguyên, gồm cả chuyển động trên X, Bluesky và Mastodon. Video MP4 và MOV được lưu nguyên bản.
- Nội dung mới được lưu tại
medias/{uuid}.{ext}trên ổ đã cấu hình (local,s3hoặcr2) và thêm vào mảngmedia[]của bài đăng.
Phản hồi
Trả về bài đăng đã cập nhật, có cấu trúc giốngGET /posts/{post}, với mục vừa tải lên trong media[].
Nếu xác thực thất bại do loại tệp không được hỗ trợ, tệp quá lớn hoặc không nền tảng đang bật nào chấp nhận, API trả về 422 cùng errors.media[].
curl -X POST https://app.getkavio.app/api/posts/9f1a2b3c-4d5e-6f7a-8b9c-0d1e2f3a4b5c/media \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Accept: application/json" \
-F "media=@./photo.jpg"
{
"id": "9f1a2b3c-4d5e-6f7a-8b9c-0d1e2f3a4b5c",
"content": "Launch day!",
"media": [
{
"id": "01HX1A2B3C4D5E6F7G8H9I0J1K",
"path": "medias/2681a1bf-131f-41b1-9866-755c1cb51f97.jpg",
"url": "https://media.getkavio.app/medias/2681a1bf-131f-41b1-9866-755c1cb51f97.jpg",
"type": "image",
"mime_type": "image/jpeg",
"original_filename": "photo.jpg"
}
],
"status": "draft",
"scheduled_at": null,
"published_at": null,
"platforms": [],
"labels": [],
"created_at": "2025-01-14 09:00:00",
"updated_at": "2025-01-14 09:30:00"
}

