Inserting items into S3 undermines with boto

Say that on S3

The following bucket set is installed:

MyBucket / MySubBucket

And I plan to use static media for the website from MySubBucket (for example, user-uploaded images, etc.). It seems that S3 configurations are currently configured, there is no way to make the top-level MyBucket bucket public, so to simulate you need to make each individual item in this bucket public after adding it.

You can make a sub bucket like "MySubBucket", but the problem I'm currently facing is trying to figure out how to call boto to insert a test image into this bucket? Can anyone provide an example?

thanks

+4
source share
1 answer

In fact, you just need to put the name of the subcategory and / in front of the file name. The following code snippet will place a file called 'test.jpg' . k.make_public() makes this file publicly available, but not necessarily by the bucket itself.

 from boto.s3.connection import S3Connection from boto.s3.key import Key connection = S3Connection(AWSKEY,AWS_SECRET_KEY) bucket = connection.get_bucket('MyBucket') file = 'test.jpg' k = Key(bucket) k.key = 'MySubBucket/' + file k.set_contents_from_filename(file) k.make_public() 
+2
source

All Articles