Skip to content
dhanu docs
Browse pages

API reference

Upload a file

POST /api/pub/v1/files, upload a file into the key creator's drive in one multipart request.

POSThttps://api.dhanu.ai/api/pub/v1/files

Uploads one file in a single multipart request (field file) into the personal drive of the person who created the key. The returned id works everywhere a file id does, attach it to a task with fileIds on create a task or send a message, or download it later.

For anything larger than the single-request limit, use the presigned upload instead. Uploads count against the workspace storage quota; a full drive answers storage_quota_exceeded.

Request

curl -X POST https://api.dhanu.ai/api/pub/v1/files \
  -H "Authorization: Bearer $DHANU_API_KEY" \
  -F "file=@notes.txt"
const file = await dhanu.files.upload({
  data: await fs.readFile("notes.txt"),
  filename: "notes.txt",
  mimeType: "text/plain",
});
with open("notes.txt", "rb") as fh:
    file = dhanu.files.upload(data=fh.read(), filename="notes.txt", mime_type="text/plain")

Response

201 Created

{ "file": { "id": "…", "filename": "notes.txt", "mimeType": "text/plain", "sizeBytes": 5, "kind": "file", "createdAt": "…" } }

Errors

CodeStatusMeaning
invalid_api_key401The bearer key is missing or unknown.
api_key_revoked401The key was revoked.
api_key_expired401The key passed its expiry date.
api_key_ip_not_allowed403The caller's IP is outside the key's allowlist.
developer_access_revoked403The key's creator lost developer access in the workspace.
api_key_project_scope403The key covers no active projects, or projectId is outside its scope.
invalid_request_body422The body did not match the schema; error.issues names each field.
unsupported_media_type415The file type is not accepted.
file_too_large413The file is larger than the direct-upload limit.
storage_quota_exceeded507The workspace's storage quota is full.