2017-02-28 178 views
0

我正嘗試使用aws SDK將XML文件從一個存儲桶上傳到另一個存儲桶。使用java將XML文件上傳到AWS s3

// Download the XML from S3 into a stream 
     AmazonS3 s3Client = new AmazonS3Client(); 
     S3Object s3Object = s3Client.getObject(new GetObjectRequest(
       srcBucket, srcKey)); 
     InputStream objectData = s3Object.getObjectContent(); 

,並上傳的文件,

s3Client.putObject(dstBucket, dstKey, objectData, meta); 

執行lambda函數拋出

More data read than expected: dataLength=367; expectedLength=1; ... 

有什麼我失蹤了呢?請幫忙。

回答

0

既然是從源到目的地桶同一對象的複製,我們可以使用

CopyObjectRequest copyObjRequest = new CopyObjectRequest(
      srcBucket, srcKey, dstBucket, dstKey); 
    s3Client.copyObject(copyObjRequest);