插入使用博托S3在分桶项 [英] Inserting items in sub-buckets on S3 using boto

查看:148
本文介绍了插入使用博托S3在分桶项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有下面的水桶上设置S3

Say I have the following bucket set up on S3

MyBucket / MySubBucket

MyBucket/MySubBucket

和,我就准备提供静态媒体网站进行MySubBucket的(如图像用户上传,等)。 S3的配置出现的方式来当前设置,有没有办法让顶级斗MyBucket公开,所以你需要让每一个个别项目在斗市民已插入后模仿这一点。

And, I am planning on serving static media for a website out of MySubBucket (like images users have uploaded, etc.). The way the S3 configurations appear to be currently set up, there is no way to make the top-level bucket "MyBucket" public, so to mimic this you need to make every individual item in that bucket public after it has been inserted.

可以,做一个分斗状MySubBucket公开,但我目前遇到的问题是试图找出如何调用博托插入测试图像成水桶?任何人都可以提供一个例子吗?

You can, make a sub-bucket like "MySubBucket" public, but the problem I am currently having is trying to figure out how to call boto to insert a test image into that bucket? Can anyone provide an example?

感谢

推荐答案

您实际上只是需要把分桶名称和 / 前的文件名。下面code段将提出一个名为test.jpg放在进入MySubBucket文件。该 k.make_public()使得该文件公开,但不一定桶本身。

You actually just need to put the sub bucket name and a / before the file name. The following code snippet will put a file called 'test.jpg' into MySubBucket. The k.make_public() makes that file public, but not necessarily 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()

这篇关于插入使用博托S3在分桶项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆