0

Download content from a file column

by
Published Apr 8, 2025

Retrieves the file content from a file column

Script xata Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Xata = {
3
	apiKey: string
4
	workspaceUrl: string
5
}
6
/**
7
 * Download content from a file column
8
 * Retrieves the file content from a file column
9
 */
10
export async function main(
11
	auth: Xata,
12
	db_branch_name: string,
13
	table_name: string,
14
	record_id: string,
15
	column_name: string
16
) {
17
	const url = new URL(
18
		`${auth.workspaceUrl}/db/${db_branch_name}/tables/${table_name}/data/${record_id}/column/${column_name}/file`
19
	)
20

21
	const response = await fetch(url, {
22
		method: 'GET',
23
		headers: {
24
			Authorization: 'Bearer ' + auth.apiKey
25
		},
26
		body: undefined
27
	})
28
	if (!response.ok) {
29
		const text = await response.text()
30
		throw new Error(`${response.status} ${text}`)
31
	}
32
	return await response.text()
33
}
34