Spaces create Quick Share link, for an individual item

March 4, 2018 153 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.

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.

Have another answer? Share your knowledge.