0

I'm uploading pdf's to s3 bucket right now all present on base directory ,using this code

  def connect_S3(self):
        return boto3.client('s3',
                            region_name=AWS_REGION,
                            aws_access_key_id=AWS_ACCESS_KEY_ID,
                            aws_secret_access_key=AWS_SECRET_ACCESS_KEY)

    s3_client=return of connect_S3()
    def upload_to_s3(self, s3_client, img_path, img_name):
        while True:
            try:
                s3_client.upload_file(img_path, AWS_S3_BUCKET, img_name)
                break
            except Exception as e:
                print(e)

but this code uploads my files to base directory is there any way i can create a Folder and upload every file into a particular folder

Robin
  • 49
  • 1
  • 9

1 Answers1

4

S3 doesn't actually have a notion of "folders" - but it's a common convention to use slashes in object keys to give the appearance of folders. There's no need to pre-create a destination folder on the remote side or anything like that. Just upload with a destination path of my_pictures/july/img1.png etc.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
gcbenison
  • 11,723
  • 4
  • 44
  • 82
  • so if i will send ```photos\img.jpg``` as my filename it create a folder(key) of name photos and then will add img.jpg there – Robin Jul 24 '21 at 18:48
  • That's the idea, though every example I've seen has used the unix convention of a forward slash as the separator, i.e. `photos/img.jpg`. – gcbenison Jul 24 '21 at 19:45