Skip to content

File Operations

storage upload download delete replace files guide

This guide covers the core file operations available through the Storage API.

Upload one or more files. Each uploaded file returns its metadata including the generated id.

const response = await nhost.storage.uploadFiles({
'bucket-id': 'default',
'file[]': [selectedFile],
})
const uploadedFile = response.body.processedFiles?.[0]

Download a file by its ID. The response body contains the raw file content.

const response = await nhost.storage.getFile(fileId)
const url = URL.createObjectURL(response.body)
window.open(url, '_blank')
// Download with image transformation (e.g. thumbnails)
const { body } = await nhost.storage.getFile(fileId, {
w: 100,
h: 100,
f: 'webp',
})
const url = URL.createObjectURL(body)

Replace file content while keeping the same file ID. References to the file remain valid.

await nhost.storage.replaceFile(fileId, { file: newFile })

The replace operation temporarily sets is_uploaded to false during the update, then restores it to true when complete.

Permanently delete a file and its metadata.

await nhost.storage.deleteFile(fileId)

The Storage REST API handles file content operations. To list, search, or filter files, use the GraphQL API:

const response = await nhost.graphql.request<{
files: Array<{ id: string; name: string; size: number; mimeType: string; bucketId: string; uploadedByUserId: string }>
}>({
query: `query GetFiles {
files {
id
name
size
mimeType
bucketId
uploadedByUserId
}
}`,
})
const files = response.body.data?.files ?? []

This is the same GraphQL API used for the rest of your application data. Permissions are evaluated automatically based on the user’s session.