Search code examples
amazon-s3trailing-slash

Upload files with name contains trailing slash to AWS S3 bucket


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.


Solution

  • 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.