Spaces create Quick Share link, for an individual item

Posted March 4, 2018 3.8k views
Block Storage

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.

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.

Submit an Answer
1 answer

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',

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'},

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.