Question

Spaces create Quick Share link, for an individual item

I want to create Quick Share link, for an individual file on digital ocean spaces so that Anyone with the link will be able to view a private file during the specified time interval. I am using Django . An assistance will be appreciated.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You can create a “Quick Share link” by generating a “pre-signed” URL using boto3 or another Python client library for S3-compatible object storage services.

With boto3, you first need to configure your session:

import os
import boto3
from botocore.client import Config

session = boto3.session.Session()
key = os.getenv('SPACES_KEY')
secret = os.getenv('SPACES_SECRET')

client = session.client('s3',
                        region_name='nyc3',
                        endpoint_url='https://nyc3.digitaloceanspaces.com',
                        aws_access_key_id=key,
                        aws_secret_access_key=secret)

Then you can generate a functioning pre-signed url using:

url = client.generate_presigned_url(ClientMethod='get_object', 
                                    Params={'Bucket': 'my-space',
                                            'Key': 'my-file'},
                                    ExpiresIn=300)

Note the ExpiresIn argument. By default, pre-signed URLs will expire in an hour (3600 seconds). This example sets it to expire in 5 minutes. See the boto3 docs for more info.