Budibase/budibase · error · HTTPError
Knowledge base file is missing object key
Error message
Knowledge base file is missing object key
What it means
Thrown by getFileUrlForOperation when a knowledge base file record exists but has no objectStoreKey. The objectStoreKey is required to generate a presigned URL in the APPS bucket, so a file without one cannot be downloaded or linked.
Source
Thrown at packages/server/src/sdk/workspace/ai/rag/files.ts:327
operationId: string,
fileId: string
): Promise<string> => {
const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)
const fileKnowledgeBaseId = file.knowledgeBaseId
if (!fileKnowledgeBaseId) {
throw new HTTPError("Invalid knowledge base file id", 400)
}
const knowledgeBaseIds = await getKnowledgeBaseIdsForOperation(
agentId,
operationId
)
if (!knowledgeBaseIds.includes(fileKnowledgeBaseId)) {
throw new HTTPError("File does not belong to this operation", 404)
}
if (!file.objectStoreKey) {
throw new HTTPError("Knowledge base file is missing object key", 400)
}
return await objectStore.getPresignedUrl(
ObjectStoreBuckets.APPS,
file.objectStoreKey
)
}
const getKnowledgeBaseIdsForAgent = async (
agentId: string
): Promise<string[]> => {
const agent = await agentsSdk.getOrThrow(agentId)
return (
agent.operations?.flatMap(operation => operation.knowledgeBases || []) || []
).filter(Boolean)
}
export const listFilesForAgent = async (View on GitHub (pinned to a81a902e9a)
Solutions
- Re-upload the file so a fresh record with a valid objectStoreKey is created
- Verify the upload pipeline persists objectStoreKey before the file record is considered ready
- Check the file record in the database to confirm objectStoreKey is populated
Example fix
// before
const url = await getFileUrlForOperation({ operationId, fileId })
// after
const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)
if (!file.objectStoreKey) {
// re-upload or surface a proper 'file not ready' state to the user
throw new Error(`File ${fileId} has no object store key; re-upload required`)
}
const url = await getFileUrlForOperation({ operationId, fileId }) Defensive patterns
Strategy: validation
Validate before calling
const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)
if (!file.objectStoreKey) throw new Error(`File ${fileId} has no object store key`) Type guard
const hasObjectStoreKey = (f: KnowledgeBaseFile): f is KnowledgeBaseFile & { objectStoreKey: string } => typeof f.objectStoreKey === "string" && f.objectStoreKey.length > 0 Try / catch
try {
const url = await getFileUrlForOperation({ operationId, fileId })
} catch (err) {
if (err instanceof HTTPError && err.status === 400) {
// treat as 'file not stored' - re-upload or show not-available state
} else throw err
} Prevention
- Only expose files to users after objectStoreKey is persisted
- Re-upload instead of retrying URL generation for records without a key
- Audit for null objectStoreKey after migrations
When it happens
Trigger: Calling getFileUrlForOperation with a fileId whose stored knowledge base file record lacks the objectStoreKey field (e.g. an upload that never completed object-store registration).
Common situations: Partially failed file uploads, records created by an older version before objectStoreKey was persisted, or manually inserted/corrupted DB rows.
Related errors
- Knowledge base file does not have an object key
- Cannot store document without _id field.
- Invalid object store key: path traversal is not allowed.
- Access denied to object store bucket.${err}
- Stream to upload is invalid/undefined
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/7db4ad2ffc33fa65.
Report an issue: GitHub.