Create file record
Create a file record after uploading. This endpoint should be called AFTER uploading the file using the presigned URL from /files/upload-url. It creates the database record and updates storage usage tracking.
# Step 1: Get presigned upload URL
curl -X POST https://app.mavera.io/api/v1/files/upload-url \
-H "Authorization: Bearer mvra_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"file_name": "document.pdf",
"file_type": "application/pdf",
"file_size": 1048576,
"workspace_id": "ws_abc123"
}'
# Step 2: Upload file to the presigned URL (use upload_url from step 1)
curl -X PUT "PRESIGNED_URL_FROM_STEP_1" \
-H "Content-Type: application/pdf" \
--data-binary @document.pdf
# Step 3: Create the file record (use public_url from step 1)
curl -X POST https://app.mavera.io/api/v1/files \
-H "Authorization: Bearer mvra_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"name": "document.pdf",
"type": "application/pdf",
"url": "PUBLIC_URL_FROM_STEP_1",
"workspace_id": "ws_abc123",
"file_size": 1048576
}'import requests
api_key = "mvra_live_your_key_here"
headers = {"Authorization": f"Bearer {api_key}"}
# Step 1: Get presigned upload URL
upload_response = requests.post(
"https://app.mavera.io/api/v1/files/upload-url",
headers=headers,
json={
"file_name": "document.pdf",
"file_type": "application/pdf",
"file_size": 1048576,
"workspace_id": "ws_abc123"
}
).json()
# Step 2: Upload file to presigned URL
with open("document.pdf", "rb") as f:
requests.put(
upload_response["upload_url"],
data=f,
headers={"Content-Type": "application/pdf"}
)
# Step 3: Create the file record
file = requests.post(
"https://app.mavera.io/api/v1/files",
headers=headers,
json={
"name": "document.pdf",
"type": "application/pdf",
"url": upload_response["public_url"],
"workspace_id": "ws_abc123",
"file_size": 1048576
}
).json()
print(f"File created: {file['id']}")const apiKey = "mvra_live_your_key_here";
const headers = {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
};
// Step 1: Get presigned upload URL
const uploadResponse = await fetch(
"https://app.mavera.io/api/v1/files/upload-url",
{
method: "POST",
headers,
body: JSON.stringify({
file_name: "document.pdf",
file_type: "application/pdf",
file_size: 1048576,
workspace_id: "ws_abc123"
})
}
).then(r => r.json());
// Step 2: Upload file to presigned URL
await fetch(uploadResponse.upload_url, {
method: "PUT",
body: fileBuffer,
headers: { "Content-Type": "application/pdf" }
});
// Step 3: Create the file record
const file = await fetch("https://app.mavera.io/api/v1/files", {
method: "POST",
headers,
body: JSON.stringify({
name: "document.pdf",
type: "application/pdf",
url: uploadResponse.public_url,
workspace_id: "ws_abc123",
file_size: 1048576
})
}).then(r => r.json());
console.log("File created:", file.id);package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.mavera.io/api/v1/files"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"url\": \"<string>\",\n \"workspace_id\": \"<string>\",\n \"file_size\": 2,\n \"folder_id\": \"<string>\",\n \"metadata\": {}\n}")
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))
}{
"id": "<string>",
"object": "file",
"name": "<string>",
"url": "<string>",
"type": "<string>",
"size": 123,
"source": "upload",
"workspace_id": "<string>",
"folder_id": "<string>",
"folder": {
"id": "<string>",
"name": "<string>"
},
"thumbnail_url": "<string>",
"metadata": {},
"is_favorite": true,
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}{
"error": {
"message": "Invalid API key.",
"type": "authentication_error",
"code": "invalid_api_key",
"param": null
}
}{
"error": {
"message": "Invalid API key.",
"type": "authentication_error",
"code": "invalid_api_key",
"param": null
}
}{
"error": {
"message": "Invalid API key.",
"type": "authentication_error",
"code": "invalid_api_key",
"param": null
}
}{
"error": {
"message": "Invalid API key.",
"type": "authentication_error",
"code": "invalid_api_key",
"param": null
}
}Authorizations
API key prefixed with mvra_live_. Create keys at Settings > Developer > API Keys.
Body
File name
MIME type of the file
Public URL where the file was uploaded (from upload-url response)
Workspace to store the file in
File size in bytes
x >= 1Optional folder ID to organize the file
Optional custom metadata
Response
File created successfully
A file/asset stored in Mavera
Unique file identifier
file File name
Direct URL to access the file
MIME type of the file (e.g., 'image/png', 'application/pdf')
File size in bytes
Source of the file upload
upload, google_drive, dropbox, dropbox_chooser, onedrive, onedrive_picker, url Workspace ID
Folder ID if file is in a folder
Folder details if file is in a folder
Show child attributes
Show child attributes
Thumbnail URL for images/videos
Custom metadata attached to the file
Whether the file is in your favorites
# Step 1: Get presigned upload URL
curl -X POST https://app.mavera.io/api/v1/files/upload-url \
-H "Authorization: Bearer mvra_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"file_name": "document.pdf",
"file_type": "application/pdf",
"file_size": 1048576,
"workspace_id": "ws_abc123"
}'
# Step 2: Upload file to the presigned URL (use upload_url from step 1)
curl -X PUT "PRESIGNED_URL_FROM_STEP_1" \
-H "Content-Type: application/pdf" \
--data-binary @document.pdf
# Step 3: Create the file record (use public_url from step 1)
curl -X POST https://app.mavera.io/api/v1/files \
-H "Authorization: Bearer mvra_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"name": "document.pdf",
"type": "application/pdf",
"url": "PUBLIC_URL_FROM_STEP_1",
"workspace_id": "ws_abc123",
"file_size": 1048576
}'import requests
api_key = "mvra_live_your_key_here"
headers = {"Authorization": f"Bearer {api_key}"}
# Step 1: Get presigned upload URL
upload_response = requests.post(
"https://app.mavera.io/api/v1/files/upload-url",
headers=headers,
json={
"file_name": "document.pdf",
"file_type": "application/pdf",
"file_size": 1048576,
"workspace_id": "ws_abc123"
}
).json()
# Step 2: Upload file to presigned URL
with open("document.pdf", "rb") as f:
requests.put(
upload_response["upload_url"],
data=f,
headers={"Content-Type": "application/pdf"}
)
# Step 3: Create the file record
file = requests.post(
"https://app.mavera.io/api/v1/files",
headers=headers,
json={
"name": "document.pdf",
"type": "application/pdf",
"url": upload_response["public_url"],
"workspace_id": "ws_abc123",
"file_size": 1048576
}
).json()
print(f"File created: {file['id']}")const apiKey = "mvra_live_your_key_here";
const headers = {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
};
// Step 1: Get presigned upload URL
const uploadResponse = await fetch(
"https://app.mavera.io/api/v1/files/upload-url",
{
method: "POST",
headers,
body: JSON.stringify({
file_name: "document.pdf",
file_type: "application/pdf",
file_size: 1048576,
workspace_id: "ws_abc123"
})
}
).then(r => r.json());
// Step 2: Upload file to presigned URL
await fetch(uploadResponse.upload_url, {
method: "PUT",
body: fileBuffer,
headers: { "Content-Type": "application/pdf" }
});
// Step 3: Create the file record
const file = await fetch("https://app.mavera.io/api/v1/files", {
method: "POST",
headers,
body: JSON.stringify({
name: "document.pdf",
type: "application/pdf",
url: uploadResponse.public_url,
workspace_id: "ws_abc123",
file_size: 1048576
})
}).then(r => r.json());
console.log("File created:", file.id);package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.mavera.io/api/v1/files"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"url\": \"<string>\",\n \"workspace_id\": \"<string>\",\n \"file_size\": 2,\n \"folder_id\": \"<string>\",\n \"metadata\": {}\n}")
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))
}{
"id": "<string>",
"object": "file",
"name": "<string>",
"url": "<string>",
"type": "<string>",
"size": 123,
"source": "upload",
"workspace_id": "<string>",
"folder_id": "<string>",
"folder": {
"id": "<string>",
"name": "<string>"
},
"thumbnail_url": "<string>",
"metadata": {},
"is_favorite": true,
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}{
"error": {
"message": "Invalid API key.",
"type": "authentication_error",
"code": "invalid_api_key",
"param": null
}
}{
"error": {
"message": "Invalid API key.",
"type": "authentication_error",
"code": "invalid_api_key",
"param": null
}
}{
"error": {
"message": "Invalid API key.",
"type": "authentication_error",
"code": "invalid_api_key",
"param": null
}
}{
"error": {
"message": "Invalid API key.",
"type": "authentication_error",
"code": "invalid_api_key",
"param": null
}
}