列出AWS S3存储桶中的所有对象 [英] List all objects in AWS S3 bucket
本文介绍了列出AWS S3存储桶中的所有对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图弄清楚如何从Swift中的AWS S3存储桶中列出所有对象.我似乎无法在Internet上的任何地方找到这些信息,但是也许我看起来不够努力.如果有人能推荐我使用允许我执行此操作的代码,那就太好了.
I am trying to figure out how to list all the objects from an AWS S3 bucket in Swift. I can't seem to find the information anywhere on the internet, but maybe I didn't look hard enough. If anyone could refer me to the code that will allow me to do this that would be great.
推荐答案
不知道您是否仍然需要它,但是在这里您可以:
Don't know if you still need it but here you go:
let credentialsProvider = AWSStaticCredentialsProvider(accessKey: "ACCESS KEY", secretKey: "SECRET KEY")
let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialsProvider)
AWSS3.registerS3WithConfiguration(configuration, forKey: "defaultKey")
let s3 = AWSS3.S3ForKey("defaultKey")
let listRequest: AWSS3ListObjectsRequest = AWSS3ListObjectsRequest()
listRequest.bucket = "BUCKET"
s3.listObjects(listRequest).continueWithBlock { (task) -> AnyObject? in
print("call returned")
let listObjectsOutput = task.result;
for object in (listObjectsOutput?.contents)! {
print(object.key)
}
return nil
}
(感谢Daniel提醒我不要使用不推荐使用的代码);)
(Thanks to Daniel for reminding me not to use deprecated code) ;)
这篇关于列出AWS S3存储桶中的所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文