问题描述
我对如何列出S3存储桶中的所有文件找不到任何好的解释感到沮丧.
I'm getting frustrated by not finding any good explanation on how to list all files in a S3 bucket.
我有大约20张图像的存储桶.我要做的就是列出它们.有人说只是使用S3.list方法".但是没有任何特殊的库,就没有S3.list方法.我有一个S3.get方法,但我无法正常工作. Arggh,如果有人告诉我如何简单地从S3存储桶中获取所有文件(文件名)的列表,我们将不胜感激.
I have this bucket with about 20 images on. All I want to do is to list them. Someone says "just use the S3.list-method". But without any special library there is no S3.list-method.I have a S3.get-method, which I dont get to work. Arggh, would appreciate if someone told me how to simply get an list of all files(filenames) from an S3 bucket.
val S3files = S3.get(bucketName: String, path: Option[String], prefix: Option[String], delimiter: Option[String])
返回未来[响应]
我不知道如何使用此S3.get.列出S3存储桶中所有文件的最简单方法是什么?
I dont know how to use this S3.get.What would be the easiest way to list all files in my S3 bucket?
非常感谢!
推荐答案
在此处使用库:
https://github.com/Rhinofly/play-s3
您应该可以执行以下操作:
You should be able to do something like this:
import concurrent.ExecutionContext.Implicits._
val bucket = S3("bucketName")
val result = bucket.list
result.map {
case Left(error) => throw new Exception("Error: " + x)
case Right(list) =>
list.foreach {
case BucketItem(name, isVirtual) => //...
}
}
您必须对凭据进行一些调整,但是示例显示了如何做到这一点.
You'll have to tweak this a bit in regards to your credentials, but the examples show how to do that.
这篇关于列出S3上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!