S3博托列表键有时返回目录关键 [英] S3 boto list keys sometimes returns directory key

查看:110
本文介绍了S3博托列表键有时返回目录关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经注意到从博托的API取决于桶的位置的回报率之间的差异。我有以下的code:

I've noticed a difference between the returns from boto's api depending on the bucket location. I have the following code:

con = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
bucket = con.get_bucket(S3_BUCKET_NAME)
keys = bucket.list(path)
for key in keys:
  print key

而即时通讯运行针对两个桶,一个在美国西部,一个在爱尔兰。在这个斗路是子目录,对阵爱尔兰我得到的子目录和任何键的下方,对我们的东西我只得到下面的钥匙。

which im running against two buckets, one in us-west and one in ireland. Path in this bucket is a sub-directory, against Ireland I get the sub directory and any keys underneath, against us-west I only get the keys beneath.

所以爱尔兰提供了:

<Key: <bucketName>,someDir/>
<Key: <bucketName>,someDir/someFile.jpg>
<Key: <bucketName>,someDir/someOtherFile.jpg>

在这里为美国标准给出了:

where as US Standard gives:

<Key: <bucketName>,someDir/someFile.jpg>
<Key: <bucketName>,someDir/someOtherFile.jpg>

很显然,我希望能够不管桶的位置写相同的code。任何人都知道我能做些什么来解决这个让我得到同样的predictable结果。或者,即使它博托造成问题的原因或S3。我注意到有不同的政策,在爱尔兰命名桶,做不同的当地人有他们自己的版本的API的?

Obviously, I want to be able to write the same code regardless of bucket location. Anyone know of anything I can do to work around this so I get the same predictable results. Or even if it's boto causing the problem or S3. I noticed there is a different policy for naming buckets in Ireland, do different locals have their own version of the api's?

谢谢

史蒂夫

推荐答案

感谢斯蒂芬,谁建议着眼于如何在密钥创建。随着进一步的调查,我觉得我有什么对这里发生的句柄。我原来suposition,它被挂斗地区是一个红色的鲱鱼。这似乎是由于什么管理控制台的功能在操作键。

Thanks to Steffen, who suggested looking at how the keys are created. With further investigation I think I've got a handle on whats happening here. My original suposition that it was linked to the bucket region was a red herring. It appears to be due to what the management console does when you manipulate keys.

如果您在管理控制台中创建一个目录它创建了一个0字节的密钥。这当您执行清单将被退回。

If you create a directory in the management console it creates a 0 byte key. This will be returned when you perform a list.

如果您使用博托创建/上传文件,那么它不会创建文件夹。有趣的是,如果你从那么一个键是为用于包含密钥的文件夹中创建的文件夹(从AWS控制台)中删除该文件。如果然后上传贝伊再次使用博托,那么你有完全一样的期待从UI结构,但逸岸你有一个虚假的附加键的目录。这是发生了什么事给我,因为我是测试我们的应用程序,我清理出键,然后找出不同的结果。

If you use boto to create/upload a file then it doesn't create the folder. Interestingly, if you delete the file from within the folder (from the AWS console) then a key is created for the folder that used to contain the key. If you then upload the bey again using boto, then you have exactly the same looking structure from the UI, but infact you have a spurious additional key for the directory. This is what was happening to me, as I was testing our application I was clearing out keys and then finding different results.

值得了解发生这种情况。有在UI无指示显示,如果一个文件夹是创建了一个(一个将返回一个键)或跨preTED一(基于一个键名)。

Worth knowing this happens. There is no indicator in the UI to show if a folder is a created one (one that will be returned as a key) or an interpreted one (based on a keys name).

这篇关于S3博托列表键有时返回目录关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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