2

I'm trying to upload some files to my bucket on S3 through boto3 on Python.

These files name are websites addresses (for example www.google.com/gmail).

I want the file name to be the website address, but in fact it creates a folder with name "www.google.com" and inside the uploaded file with name "gmail"

I tried to solve it with double slash and backslash before the trailing slash, but it didn't work.

Is there any way to ignore the trailing slash and upload a file that its name is a website address?

Thanks.

morkan
  • 171
  • 2
  • 3
  • 6

2 Answers2

7

You are misunderstanding S3 - it does not actually have a "folder" structure. Every object in a bucket has a unique key, and the object is accessed via that key.

Some S3 utilities (including to be fair the AWS console) fake up a "folder" structure, but this isn't too relevant to how S3 works.

Or in other words, don't worry about it. Just create the object with / in its key and everything will work as you expect.

Philip Kendall
  • 4,304
  • 1
  • 23
  • 42
2

S3 has a flat structure with no folders. The "folders" you are seeing are a feature in the AWS Console to make it easier to navigate through your objects. The console will group objects in a "folder" based on the prefix before the slash (if there is one).

There's nothing that prevents you from using slashes in S3 object keys. When you use the API via boto, you can refer to the full URL and you should get the object.

See: https://docs.aws.amazon.com/AmazonS3/latest/user-guide/using-folders.html

Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443