为了在S3中复制文件,我使用的是vfs-s3-2.2.1.jar,我在com.intridea.io.vfs.provider.s3包下找到了S3FileObject类。我在其中使用复制文件的方法。在这种方法中,我发现以下代码:public void copyFrom(final FileObject file, final FileSelector selector)
try {
if (srcFile.getType().hasChildren()) {
destFile.createFolder();
// do server side copy if both source and dest are in S3 and using same credentials
} else if (srcFile instanceof S3FileObject) {
S3FileObject s3SrcFile = (S3FileObject)srcFile;
String srcBucketName = s3SrcFile.getBucket().getName();
String srcFileName = s3SrcFile.getS3Key();
String destBucketName = destFile.getBucket().getName();
String destFileName = destFile.getS3Key();
CopyObjectRequest copy = new CopyObjectRequest(
srcBucketName, srcFileName, destBucketName, destFileName);
if (srcFile.getType() == FileType.FILE && getServerSideEncryption()) {
ObjectMetadata meta = s3SrcFile.getObjectMetadata();
meta.setSSEAlgorithm(AES_256_SERVER_SIDE_ENCRYPTION);
copy.setNewObjectMetadata(meta);
}
getService().copyObject(copy);
} else if (srcFile.getType().hasContent() && srcFile.getURL().getProtocol().equals("file")) {
// do direct upload from file to avoid overhead of making a copy of the file
try {
File localFile = new File(srcFile.getURL().toURI());
destFile.upload(localFile);
} catch (URISyntaxException e) {
// couldn't convert URL to URI, but should still be able to do the slower way
super.copyFrom(file, selector);
}
} else {
super.copyFrom(file, selector);
}
} catch (IOException e) {
throw new FileSystemException("vfs.provider/copy-file.error", new Object[]{srcFile, destFile}, e);
} catch (AmazonClientException e) {
throw new FileSystemException("vfs.provider/copy-file.error", new Object[]{srcFile, destFile}, e);
} finally {
destFile.close();
}
withSourceSSECustomerKey(sseKey)
withDestinationSSECustomerKey(newSseKey);
在vfs-s3-2.2.1.jar S3FileObject的copyFrom方法中,找不到任何设置SSECustomerKey的方法。如何实现相同的目的。感谢您在这里寻找。
我没有测试,但是我快速查看了lib /代码-在https://github.com/abashev/vfs-s3/blob/branch-2.3.x/src/main/java/com/intridea/io/vfs中/provider/s3/S3FileSystemConfigBuilder.java有一种设置服务器端加密的方法
/**
* use server-side encryption.
*
* @param opts The FileSystemOptions.
* @param serverSideEncryption true if server-side encryption should be used.
*/
public void setServerSideEncryption(FileSystemOptions opts, boolean serverSideEncryption)
{
setParam(opts, SERVER_SIDE_ENCRYPTION, serverSideEncryption);
}
因此,在致电之前,copyFrom
您可以做
S3FileSystemConfigBuilder.getInstance().setServerSideEncryption(
S3FileSystemConfigBuilder.getInstance().getFileSystem().getFileSystemOptions(),
true);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句