How to upload an object to digital ocean spaces using python boto3 library.

November 27, 2017 150 views
Python DigitalOcean Ubuntu 16.04

I am trying to automated some of my task related to digialocean spaces.
but stuck at when i a trying to upload an object to spaces. and i also want to know is there any way to set expiration tag on the object.

1 Answer

To answer the second question first, Spaces does not currently support "lifecycle" events. So unfortunately you can not use expiration tags at this time.

For the question in the title, uploading an object to Spaces using boto3 requires that you edit the endpoint setting for the session. Here's a quick example:

import boto3

session = boto3.session.Session()
client = session.client('s3',
                        region_name='nyc3',
                        endpoint_url='https://nyc3.digitaloceanspaces.com',
                        aws_access_key_id='ACCESS_KEY',
                        aws_secret_access_key='SECRET_KEY')

client.upload_file('/path/to/file.ext',  # Path to local file
                   'my-space',  # Name of Space
                   'file.ext')  # Name for remote file
Have another answer? Share your knowledge.