2

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?

Atom Store
  • 961
  • 1
  • 11
  • 35

1 Answers1

2

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.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • so I need to create function which iterate over all the files – Atom Store Nov 15 '21 at 07:42
  • 1
    @AtomStore Yes. Or look for existing, third party ones, such as https://gist.github.com/hari116/4ab5ebd885b63e699c4662cd8382c314/ . This is a common problem, and there are many boto3 code snippets available for that. You can also use AWS CLI, even from python, if you want. – Marcin Nov 15 '21 at 07:46