AWS S3 Java SDK未将文件复制到文件夹

时间:2019-01-07 17:22:17

标签: java amazon-web-services amazon-s3

Java 8在这里。我有一个具有以下文件夹子结构的S3存储桶(myapp-bucket):

/artwork
    /upload
    /staging

myapp-bucket/artwork文件夹如下所示:

enter image description here

我有将图像文件上传到/upload文件夹的软件,然后我正在编写的另一个应用程序将处理该图像并将其复制到/staging文件夹中。我要执行此S3复制的代码如下:

CopyObjectRequest copyObjectRequest = new CopyObjectRequest(
  bucketName,
  objectKey,
  destinationBucket,
  destinationKey
);

log.info(
  "copying object from s3://{}/{} to s3://{}/{}",
  bucketName,
  objectKey,
  destinationBucket,
  destinationKey
);

// Constructed via 
AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
amazonS3.copyObject(copyObjectRequest);

运行时,我看到以下日志输出:

[main] DEBUG com.me.myapp.ImageProcessor - copying object from s3://myapp-bucket/artwork/upload/rlj_amp244001_270.jpeg to s3://myapp-bucket/artwork/staging

但是myapp-bucket/artwork文件夹的最终状态如下:

enter image description here

看起来,与其将myapp-bucket/artwork/upload/<theImageFile>复制到myapp-bucket/artwork/staging/目录,而是在/artwork的正下方创建一个新的 file 并将其命名为{{1 }},并可能将图像的二进制内容复制到该登台文件中。我要去哪里了?!我只想以staging结尾-预先感谢!

1 个答案:

答案 0 :(得分:5)

S3没有文件夹/目录-只是平面存储中的糖。因此,您的destinationKey应该看起来像artwork/staging/rlj_amp244001_270.jpeg