使用 JetS3t 将未知数量的文件多次上传到 S3
从jetS3t的示例代码示例中,代码如下: 如果我不知道要下载的文件数量该怎么办 开始? 例如,S3 中带有缩略图的应用程序和客户端应用程序 用户滚动浏览缩略图列表。
下载对象到本地文件
多线程服务提供了下载的方法 一次多个对象,但是 要使用它,您必须首先准备一个地方来放置 与每个对象相关的数据。 放置这些数据的最明显的地方就是文件,所以 让我们来看一个例子 将对象数据下载到文件中。 要将我们的对象下载到文件中,我们首先必须创建一个 下载包类 每个对象。这个类是一个简单的容器,仅 将一个对象与一个关联 文件,对象的数据将写入其中。 为每个对象创建一个DownloadPackage,以关联 带有输出文件的对象。
DownloadPackage[] downloadPackages = new DownloadPackage[5];
downloadPackages[0] = new DownloadPackage(objects[0],
new File(objects[0].getKey()));
downloadPackages[1] = new DownloadPackage(objects[1],
new File(objects[1].getKey()));
downloadPackages[2] = new DownloadPackage(objects[2],
new File(objects[2].getKey()));
downloadPackages[3] = new DownloadPackage(objects[3],
new File(objects[3].getKey()));
downloadPackages[4] = new DownloadPackage(objects[4],
new File(objects[4].getKey()));
// Download the objects.
simpleMulti.downloadObjects(bucket, downloadPackages);
System.out.println("Downloaded objects to current working directory");
对于这些案例有什么建议吗? 预先感谢
安东尼斯
from the sample code examples of jetS3t the code that follows:
What to do if I don't know the number of files to be downloaded from
the beginning?
E.g an application with thumbnails in S3, and a client application
that the user scrolls through a list of thumbnails.
Download objects to local files
The multi-threading services provide a method to download
multiple objects at a time, but
to use this you must first prepare somewhere to put the
data associated with each object.
The most obvious place to put this data is into a file, so
let's go through an example of
downloading object data into files.
To download our objects into files we first must create a
DownloadPackage class for
each object. This class is a simple container which merely
associates an object with a
file, to which the object's data will be written.
Create a DownloadPackage for each object, to associate the
object with an output file.
DownloadPackage[] downloadPackages = new DownloadPackage[5];
downloadPackages[0] = new DownloadPackage(objects[0],
new File(objects[0].getKey()));
downloadPackages[1] = new DownloadPackage(objects[1],
new File(objects[1].getKey()));
downloadPackages[2] = new DownloadPackage(objects[2],
new File(objects[2].getKey()));
downloadPackages[3] = new DownloadPackage(objects[3],
new File(objects[3].getKey()));
downloadPackages[4] = new DownloadPackage(objects[4],
new File(objects[4].getKey()));
// Download the objects.
simpleMulti.downloadObjects(bucket, downloadPackages);
System.out.println("Downloaded objects to current working directory");
Any suggestions for that cases?
Thanks in advance
Antonis
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以列出下载的存储桶中的对象,并根据您定义的规则过滤密钥。然后您就可以开始分段下载。
从存储桶中获取密钥:
<代码>
过滤密钥后,您可以下载密钥列表的特定部分。
You can list the objects in the bucket you download from and filter keys according to the rules you define. Then you can start a multipart download.
get keys from the bucket:
after filtering the keys you can download particular part of the key-list.