Upload an asset
An upload link for one file; PUT the bytes to it.
curl https://api.muzekit.com/v1/assets/uploads \
-H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "logo.png", "type": "image/png", "brand": true }'
curl -X PUT "$UPLOAD_URL" -H "Content-Type: image/png" --data-binary @logo.pngimport { readFile } from "node:fs/promises";
const res = await fetch("https://api.muzekit.com/v1/assets/uploads", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ name: "logo.png", type: "image/png", brand: true }),
});
const upload = await res.json();
await fetch(upload.upload_url, {
method: "PUT",
headers: { "Content-Type": "image/png" },
body: await readFile("logo.png"),
});import os
import requests
# json= sends the body with Content-Type: application/json
upload = requests.post(
"https://api.muzekit.com/v1/assets/uploads",
headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
json={"name": "logo.png", "type": "image/png", "brand": True},
).json()
with open("logo.png", "rb") as f:
requests.put(upload["upload_url"], headers={"Content-Type": "image/png"}, data=f)| Field | |
|---|---|
name, type | The file name and MIME type |
size | Optional; refused early when over the limit |
kind | Optional: image, video, audio, font (read from type otherwise) |
family | Fonts: the family name in the font list |
user | Upload into this end user's library |
brand | Add to the editor's brand kit (not with user) |
The link works once, for 15 minutes. The PUT answers with the file's id, url, width and height; Muzekit reads the type from the bytes and refuses files that don't match, are over the limit, or are unsafe SVGs.
Without user or brand, the file goes into the workspace library. Uploading the same file again to the same library gives back the asset it already has.
Examples
Upload into an end user's library
Send user to put the file in that end user's own uploads. They see it every time they open the editor, and other users don't.
UPLOAD_URL=$(curl -s https://api.muzekit.com/v1/assets/uploads \
-H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "photo.jpg", "type": "image/jpeg", "user": "usr_8fK2mQ1xZpR" }' \
| jq -r .upload_url)
curl -X PUT "$UPLOAD_URL" -H "Content-Type: image/jpeg" --data-binary @photo.jpgimport { readFile } from "node:fs/promises";
const res = await fetch("https://api.muzekit.com/v1/assets/uploads", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "photo.jpg",
type: "image/jpeg",
user: "usr_8fK2mQ1xZpR",
}),
});
const upload = await res.json();
const put = await fetch(upload.upload_url, {
method: "PUT",
headers: { "Content-Type": "image/jpeg" },
body: await readFile("photo.jpg"),
});
const asset = await put.json(); // asset.id is the new ast_… idimport os
import requests
upload = requests.post(
"https://api.muzekit.com/v1/assets/uploads",
headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
json={"name": "photo.jpg", "type": "image/jpeg", "user": "usr_8fK2mQ1xZpR"},
).json()
with open("photo.jpg", "rb") as f:
asset = requests.put(
upload["upload_url"], headers={"Content-Type": "image/jpeg"}, data=f
).json()The PUT answers with the stored file:
{
"url": "https://storage.muzekit.com/…/photo.jpg",
"type": "image/jpeg",
"size": 482113,
"width": 1600,
"height": 1200,
"id": "ast_dQC3Z8RgqAH"
}Add a font to the brand kit
Send "brand": true and the family name the font list should show. Upload one file per weight, each with the same family.
UPLOAD_URL=$(curl -s https://api.muzekit.com/v1/assets/uploads \
-H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Acme-Bold.woff2",
"type": "font/woff2",
"family": "Acme",
"brand": true
}' \
| jq -r .upload_url)
curl -X PUT "$UPLOAD_URL" -H "Content-Type: font/woff2" --data-binary @Acme-Bold.woff2import { readFile } from "node:fs/promises";
const res = await fetch("https://api.muzekit.com/v1/assets/uploads", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "Acme-Bold.woff2",
type: "font/woff2",
family: "Acme",
brand: true,
}),
});
const upload = await res.json();
await fetch(upload.upload_url, {
method: "PUT",
headers: { "Content-Type": "font/woff2" },
body: await readFile("Acme-Bold.woff2"),
});import os
import requests
upload = requests.post(
"https://api.muzekit.com/v1/assets/uploads",
headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
json={
"name": "Acme-Bold.woff2",
"type": "font/woff2",
"family": "Acme",
"brand": True,
},
).json()
with open("Acme-Bold.woff2", "rb") as f:
requests.put(upload["upload_url"], headers={"Content-Type": "font/woff2"}, data=f)Upload a video
Videos are uploaded the same way. Send size too, so a file over the video limit (413 file_too_large) or over your plan's storage (402 storage_full) is refused before you send the bytes.
SIZE=$(wc -c < promo.mp4 | tr -d ' ')
UPLOAD_URL=$(curl -s https://api.muzekit.com/v1/assets/uploads \
-H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
-H "Content-Type: application/json" \
-d "{ \"name\": \"promo.mp4\", \"type\": \"video/mp4\", \"size\": $SIZE }" \
| jq -r .upload_url)
curl -X PUT "$UPLOAD_URL" -H "Content-Type: video/mp4" --data-binary @promo.mp4import { readFile, stat } from "node:fs/promises";
const res = await fetch("https://api.muzekit.com/v1/assets/uploads", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "promo.mp4",
type: "video/mp4",
size: (await stat("promo.mp4")).size,
}),
});
const upload = await res.json();
if (!res.ok) throw new Error(upload.error.message);
await fetch(upload.upload_url, {
method: "PUT",
headers: { "Content-Type": "video/mp4" },
body: await readFile("promo.mp4"),
});import os
import requests
res = requests.post(
"https://api.muzekit.com/v1/assets/uploads",
headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
json={
"name": "promo.mp4",
"type": "video/mp4",
"size": os.path.getsize("promo.mp4"),
},
)
res.raise_for_status()
upload = res.json()
with open("promo.mp4", "rb") as f:
requests.put(upload["upload_url"], headers={"Content-Type": "video/mp4"}, data=f)Copy a file from your own storage
When the file already lives at a URL (your bucket or CDN), download it on your server and PUT the bytes. Muzekit keeps its own copy, so the editor never loads your URL.
UPLOAD_URL=$(curl -s https://api.muzekit.com/v1/assets/uploads \
-H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "banner.png", "type": "image/png", "user": "usr_8fK2mQ1xZpR" }' \
| jq -r .upload_url)
curl -s https://cdn.example.com/banner.png \
| curl -X PUT "$UPLOAD_URL" -H "Content-Type: image/png" --data-binary @-const res = await fetch("https://api.muzekit.com/v1/assets/uploads", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "banner.png",
type: "image/png",
user: "usr_8fK2mQ1xZpR",
}),
});
const upload = await res.json();
const file = await fetch("https://cdn.example.com/banner.png");
await fetch(upload.upload_url, {
method: "PUT",
headers: { "Content-Type": "image/png" },
body: Buffer.from(await file.arrayBuffer()),
});import os
import requests
upload = requests.post(
"https://api.muzekit.com/v1/assets/uploads",
headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
json={"name": "banner.png", "type": "image/png", "user": "usr_8fK2mQ1xZpR"},
).json()
file = requests.get("https://cdn.example.com/banner.png")
requests.put(
upload["upload_url"], headers={"Content-Type": "image/png"}, data=file.content
)Response
{
"object": "upload",
"upload_url": "https://api.muzekit.com/runtime/uploads/…",
"url": "https://storage.muzekit.com/…/logo.png",
"kind": "image",
"expires_in": 900
}