0

Create Presigned Object URL

by
Published Apr 8, 2025

Returns a timed and authenticated URL to get an object. This is the equivalent to AWS S3’s “presigned” URL. Please note that Telnyx performs authentication differently from AWS S3 and you MUST NOT use the presign method of AWS s3api CLI or sdk to generate the presigned URL. Refer to: https://developers.telnyx.com/docs/cloud-storage/presigned-urls

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Create Presigned Object URL
7
 * Returns a timed and authenticated URL to get an object. This is the equivalent to AWS S3’s “presigned” URL. Please note that Telnyx performs authentication differently from AWS S3 and you MUST NOT use the presign method of AWS s3api CLI or sdk to generate the presigned URL. 
8

9
Refer to: https://developers.telnyx.com/docs/cloud-storage/presigned-urls
10

11
 */
12
export async function main(
13
	auth: Telnyx,
14
	bucketName: string,
15
	objectName: string,
16
	body: { ttl?: number }
17
) {
18
	const url = new URL(
19
		`https://api.telnyx.com/v2/storage/buckets/${bucketName}/${objectName}/presigned_url`
20
	)
21

22
	const response = await fetch(url, {
23
		method: 'POST',
24
		headers: {
25
			'Content-Type': 'application/json',
26
			Authorization: 'Bearer ' + auth.apiKey
27
		},
28
		body: JSON.stringify(body)
29
	})
30
	if (!response.ok) {
31
		const text = await response.text()
32
		throw new Error(`${response.status} ${text}`)
33
	}
34
	return await response.json()
35
}
36