Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a directory in a bucket using boto3 ? #377

Closed
tuxknight opened this issue Nov 23, 2015 · 8 comments
Closed

How to create a directory in a bucket using boto3 ? #377

tuxknight opened this issue Nov 23, 2015 · 8 comments

Comments

@tuxknight
Copy link

Does boto3 support creating directory ?
Will it create a directory name "dir" when I put an object with a key such as "dir/file.png" ?

@themanifold
Copy link

I'm pretty sure that S3 has no concept of a directory. It's designed as a key-value store, so everything within a bucket is stored on the same 'level'.

If you really want a directory-like structure (restricted to two-deep), then you can use multiple buckets.

@tuxknight
Copy link
Author

Thx @themanifold
Maybe it's not called a directory. But I can create a folder in a bucket on aws s3 console.
How could I do the samething using boto?

@jamesls
Copy link
Member

jamesls commented Nov 23, 2015

@tuxknight You would upload an empty file whose name ends with a /.

@ryantuck
Copy link

for anyone else who comes along not realizing immediately what this would entail, this is how i did it:

import boto3

client = boto3.client('s3')

response = client.put_object(
        Bucket='my-top-level-bucket',
        Body='',
        Key='test-folder/'
        )

@webraj1
Copy link

webraj1 commented Jan 8, 2017

@ryantuck Thanks, Looks like its possible with boto 3, I am trying to build directory tree like structure in s3, so for every client there is separate folder & separate sub folders for their orders placed in site. I am pretty sure we can build a very nice structure on s3, My question is this, Can we also build a file manager or file browser inside our application on top of s3 for all the client files, I am thinking of something similar like dropbox or google drive. SO I am wondering if this can be done on top of s3 file structure & there also be restriction on files to be accessed by some users. Sorry, If my question is not clear.

@phanimahi
Copy link

@ryantuck hi bro it's very good code but I have a doubt what if I want to put three folders at a time in the bucket.

@ryantuck
Copy link

@webraj1 you would probably want to use separate buckets for that. google or aws docs would probably be more helpful for telling you if you can restrict access to certain roles within the same bucket.

@phanimahi my guess is that you would not put them in 3 at a time, but rather one after the other?

@Deepakanandrao
Copy link

Deepakanandrao commented May 12, 2020

@webraj1

@ryantuck Thanks, Looks like its possible with boto 3, I am trying to build directory tree like structure in s3, so for every client there is separate folder & separate sub folders for their orders placed in site. I am pretty sure we can build a very nice structure on s3, My question is this, Can we also build a file manager or file browser inside our application on top of s3 for all the client files, I am thinking of something similar like dropbox or google drive. SO I am wondering if this can be done on top of s3 file structure & there also be restriction on files to be accessed by some users. Sorry, If my question is not clear.

Just wondering, if you got it working? I'm at the same cross-roads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants