Open 99bits opened 2 months ago
Hi @99bits - thank you for your custom!
If your video and audio files are stored in a private bucket, you can generate a presigned URL for each file that you can pass to Twelve Labs in an API call. Presigned URLs allow Twelve Labs to access the files for a limited amount of time without access to an application key.
Here's an example in Python, using the Boto3 SDK:
# Configure the client as you usually would for accessing B2, via environment variables,
# the AWS configuration file, or, as here, passing the parameters directly
client = boto3.client(
's3',
aws_access_key_id=YOUR_APPLICATION_KEY_ID,
aws_secret_access_key=YOUR_APPLICATION_KEY,
endpoint_url=YOUR_BUCKET_ENDPOINT,
region_name=YOUR_BUCKET_REGION
)
# Generate a presigned URL
# expiration is in seconds, default is 3600 (one hour)
url = s3_client.generate_presigned_url(
'get_object',
Params={'Bucket': bucket_name, 'Key': object_name},
ExpiresIn=expiration
)
Each of the AWS SDKs contains a corresponding function for generating presigned URLs.
The resulting URL looks like this (I've inserted line breaks for clarity):
https://s3.us-west-004.backblazeb2.com/metadaddy-private/HelloWorld.txt
?versionId=4_z0145cfc9e3f5ec0f74ed0c1b_f4112279d66006eed_d20240313_m222406_c004_v0402015_t0056_u01710368646689
&X-Amz-Algorithm=AWS4-HMAC-SHA256
&X-Amz-Credential=00415f935cf4dcb000000009e%2F20240924%2Fus-west-004%2Fs3%2Faws4_request
&X-Amz-Date=20240924T003912Z
&X-Amz-Expires=604800
&X-Amz-SignedHeaders=host
&X-Amz-Signature=2b33d34021a3a71cd309ff34d2716e2f8d31b4bf1249f106e7d923425d0339b0
The expiration on this example is one week, so, until Monday, September 30th, 5:39pm Pacific time, you can access it:
% curl 'https://s3.us-west-004.backblazeb2.com/metadaddy-private/HelloWorld.txt?versionId=4_z0145cfc9e3f5ec0f74ed0c1b_f4112279d66006eed_d20240313_m222406_c004_v0402015_t0056_u01710368646689&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=00415f935cf4dcb000000009e%2F20240924%2Fus-west-004%2Fs3%2Faws4_request&X-Amz-Date=20240924T003912Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=2b33d34021a3a71cd309ff34d2716e2f8d31b4bf1249f106e7d923425d0339b0'
Hello world!
After that time, attempting to access that URL will result in an error similar to:
% curl 'https://s3.us-west-004.backblazeb2.com/metadaddy-private/HelloWorld.txt?versionId=4_z0145cfc9e3f5ec0f74ed0c1b_f4112279d66006eed_d20240313_m222406_c004_v0402015_t0056_u01710368646689&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=00415f935cf4dcb000000009e%2F20240924%2Fus-west-004%2Fs3%2Faws4_request&X-Amz-Date=20240924T004632Z&X-Amz-Expires=1&X-Amz-SignedHeaders=host&X-Amz-Signature=46d1df8586974236042be1a2ed7889f8f56a9d67d3f5092b860df6d33e55a94c'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Error>
<Code>UnauthorizedAccess</Code>
<Message>Request has expired given timestamp: '20240924T004632Z' and expiration: 1</Message>
</Error>
If you get stuck, let me know what programming language you are using and I'll be happy to point you in the right direction.
Great example, thank you.
We have a backblaze account and we are using blackblaze for storing videos and audio. How can we generate a link to the video files?