Search code examples
amazon-s3boto3digital-oceanbotodigital-ocean-spaces

How to upload the folder to digital ocean spaces?


From the link, https://www.digitalocean.com/community/questions/how-to-upload-an-object-to-digital-ocean-spaces-using-python-boto3-library. It only states to upload files to the spaces.

I want to upload a folder to the spaces.

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

This only uploads file. How to upload folder or directory from this process?


Solution

  • You do it the same as with S3, which is to iterate over the files in the folder and upload all files as you iterate over them using your upload_file.

    Only AWS CLI has high level function to upload folders. boto3 can upload only individual files.