2011-03-12 37 views
0

所以我想克隆S3(Amazon S3)帐户上的文件夹中的对象。但我想知道是否有办法做到这一点,而不必先将文件写入本地系统,然后将该文件上传到S3?如何使用RestS3Service克隆Amazon S3中的对象

最终我希望它是完全递归克隆给定存储桶中的文件夹和对象,但现在我坚持让它克隆有效。

说水桶路径images.example.com/products/prodSku 并在prodSku文件夹我有一堆我要复制到一个新文件夹

图像这是我到目前为止所。

(注:这是写在Groovy的,但如果你知道的Java,这是同样的事情)

try{ 

    def s3os = restService.listObjects(bucket_name, sourcePrefix, null) 
    def s3o 
    for(def i in s3os){ 
     s3o = get(bucket_name, i.key) 
     // i want to be able to do something like this, just putting the input stream 
     // back into s3. but i can't. from what i know now, i have to write the 
     // dataInputStream into a file locally, then use that file to create a new S3Object 
     // which is placed as the second argument in the putObject method 
     restService.putObject(destinationBucketName, s3o.dataInputStream) 
    } 
}catch(S3ServiceException e) 
{ 

    println e 
} 

对不起格式是全乱了,第一次发布的消息。

但任何帮助将不胜感激!

谢谢!

回答

1

不知道有关的JetS3t API,但是,在AWS SDK for Java确实提供了一种简单的方法copyObject

+2

JetS3t复制示例是[here](http://jets3t.s3.amazonaws.com/toolkit/code-samples.html#copying)。 – 2011-03-12 05:03:31

0

,所以我最终搞清楚如何做克隆使用的JetS3t在S3中的资产。这比我想象的要简单。我会发布它以防止任何人使用这个问题。

所有的操作都是首先获取想要克隆的s3对象。获得后,请在s3对象上调用setKey(filename)。 “文件名”是你想让对象跟随文件名本身的路径,也就是yours3bucketname/products/assets/picture.png

你完成之后,只需调用putObject(bucket_name,s3object),传递你调用setKey的s3object作为第二个参数。

祝你好运!开心编程!