Report this

What is the reason for this report?

temporary links in Spaces

Posted on July 20, 2024

S3 has a feature that let’s you create short term access to files/folders DO Spaces do also support this feature, but i could not find in the documentation in how to do this via API. is there any way that this can be done externally (preparedly via php or python)?



This textbox defaults to using Markdown to format your 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.

Hey 👋

Yes, DigitalOcean Spaces, does support the creation of temporary (or pre-signed) URLs for files. This feature allows you to generate time-limited access links to private objects in your Space.

Here is a step by step documentation guide on how to do that:

https://docs.digitalocean.com/glossary/pre-signed-url

The guide above, also includes a Python example:

import boto3
from botocore.client import Config

# Initialize a session using DigitalOcean Spaces
session = boto3.session.Session()
client = session.client('s3',
                        region_name='nyc3',
                        endpoint_url='https://nyc3.digitaloceanspaces.com',
                        aws_access_key_id='YOUR_ACCESS_KEY',
                        aws_secret_access_key='YOUR_SECRET_KEY')

# Generate pre-signed URL with query parameters
url = client.generate_presigned_url(ClientMethod='get_object',
                                    Params={
                                        'Bucket': 'your-space-name',
                                        'Key': 'your-object-key',
                                        'ResponseContentType': 'text/plain',
                                        # You can add more parameters if needed, such as 'ResponseContentDisposition': 'attachment; filename=filename.txt'
                                    },
                                    ExpiresIn=3600)

Hope that this helps!

- Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.