Question:
I’m getting frustrated by not finding any good explanation on how to list all files in a S3 bucket.
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.
1 2 |
val S3files = S3.get(bucketName: String, path: Option[String], prefix: Option[String], delimiter: Option[String]) |
returns an Future[Response]
I dont know how to use this S3.get.
What would be the easiest way to list all files in my S3 bucket?
Answers much appreciated!
Answer:
Using the library here:
https://github.com/Rhinofly/play-s3
You should be able to do something like this:
1 2 3 4 5 6 7 8 9 10 11 12 |
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.