列出 S3 上的文件 [英] List files on S3

查看:30
本文介绍了列出 S3 上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何列出 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-method.我有一个 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])

返回一个 Future[Response]

returns an Future[Response]

我不知道如何使用这个 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 上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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