在我的应用程序中,我使用Amazon S3
服务器来存储数据。我正在尝试使用jets3
api将特定文件从一个位置移动到另一个位置,如下所示:
public void moveFile(String currentPath, String newPath, String fileName, boolean overWrite) throws FileException
{
S3Service s3Service = null;
try
{
s3Service = getS3Service();
String bucketFolderPath = "test-site/files/doc-lib/2015/07/16/09/05/46/552/v-6";
String currentFolderPath = "test-site/files/doc-lib/2015/07/16/09/05/46/552/head";
S3Bucket writeToLocation = s3Service.createBucket(this.bucketName + "/" + bucketFolderPath);
S3Bucket readFromLocation = s3Service.createBucket(this.bucketName + "/" + currentFolderPath);
try
{
s3Service.moveObject(currentFolderPath, "Eclipse-Shortcuts.pdf", bucketFolderPath, new S3Object("Eclipse-Shortcuts.pdf"), overWrite);
}
catch (ServiceException e)
{
e.printStackTrace();
}
}
catch (IllegalArgumentException ex)
{
throw new FileException("Could not write the file to the repository", ex);
}
catch (S3ServiceException ex)
{
throw new FileException("Could not write the file to the repository", ex);
}
finally
{
shutDownService(s3Service);
}
}
此处Eclipse-Shortcuts.pdf
是我要复制的文件的名称。
执行此方法时,我收到以下错误:
org.jets3t.service.ServiceException:S3错误消息。 PUT' /test-site/files/doc-lib/2015/07/16/09/05/46/552/v-6/Eclipse-Shortcuts.pdf'在Host' s3.amazonaws.com' @'星期二,2015年7月21日06:11:55 GMT' - ResponseCode:403,ResponseStatus:禁止,XML错误消息:
AccessDenied
访问被拒绝3C5B8A31DC582D13ulPMuZ7PqE9uUMje6 / 5Y / N7mEppYlr8BPHr60ixVwcy1LOj0sszhEDYxbEg + vypY 在org.jets3t.service.impl.rest.httpclient.RestStorageService.performRequest(RestStorageService.java:453) 在org.jets3t.service.impl.rest.httpclient.RestStorageService.performRestPut(RestStorageService.java:961) at org.jets3t.service.impl.rest.httpclient.RestStorageService.copyObjectImpl(RestStorageService.java:1831) at org.jets3t.service.StorageService.copyObject(StorageService.java:873) 在org.jets3t.service.StorageService.copyObject(StorageService.java:918) at org.jets3t.service.StorageService.moveObject(StorageService.java:967) at com.smartwcm.filestore.impl.FileStoreImpl.moveFile(FileStoreImpl.java:380) at com.smartwcm.core.file.service.impl.FileUploadServiceImpl.moveFile(FileUploadServiceImpl.java:189) at com.smartwcm.core.simplewebcontent.service.impl.SimpleWebContentServiceImpl.moveCurrentDataForDocLibEdit(SimpleWebContentServiceImpl.java:963)
我很擅长使用jets3
api。在我有这个代码的同一个类中,我有一个方法可以将文件保存到指定位置并且正常工作。唯一的问题是移动部分。