Edits history of script submission #13026 for ' Create Presigned Object URL (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Create Presigned Object URL
     * 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
    
     */
    export async function main(
    	auth: Telnyx,
    	bucketName: string,
    	objectName: string,
    	body: { ttl?: number }
    ) {
    	const url = new URL(
    		`https://api.telnyx.com/v2/storage/buckets/${bucketName}/${objectName}/presigned_url`
    	)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 428 days ago