[英]com.amazonaws.services.s3.model.AmazonS3Exception: User key must be specified
com.amazonaws.services.s3.model.AmazonS3Exception: User key must be specified. (Service: Amazon S3; Status Code: 400;
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1160)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:748)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:467)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:302)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3769)
at com.amazonaws.services.s3.AmazonS3Client.deleteObjects(AmazonS3Client.java:1841)
The code looks like below: 代码如下所示:
client.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(keys.toArray(new String[urls.length]))
access/secret keys are set up properly. 访问/密钥设置正确。
What is the user key ? 什么是用户密钥 ?
What is User Key?
什么是用户密钥?
Ans: 答:
User Key is a key by which user can get credentials. 用户密钥是用户可以获取凭据的密钥。
It verifies who you are and whether you have permission to access the resources that you are requesting
. It verifies who you are and whether you have permission to access the resources that you are requesting
。 User security credentials have Access Key ID
and Secret Access Key
. 用户安全凭证具有
Access Key ID
和Secret Access Key
。
You must store the keys in secure location.
您必须将密钥存储在安全的位置。 Your secret key will no longer be available through the AWS Management Console;
您的密钥将不再通过AWS管理控制台提供; you will have the only copy.
你将拥有唯一的副本。 Keep it confidential in order to protect your account, and never email it.
保密,以保护您的帐户,绝不发送电子邮件。 Do not share it outside your organization, even if an inquiry appears to come from AWS or Amazon.com.
即使查询似乎来自AWS或Amazon.com,也不要在您的组织外共享。 No one who legitimately represents Amazon will ever ask you for your secret key.
合法代表亚马逊的任何人都不会要求您提供密钥。
For more: http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html 更多信息: http : //docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html
Your client.deleteObjects(....);
你的
client.deleteObjects(....);
methods have keys which are processing using array. 方法具有使用数组处理的键。 But
ArrayList
is used below for deleting objects with proper exception handling
. 但是下面使用
ArrayList
来删除具有proper exception handling
对象。
Deleting Multiple Objects (Version-Enabled Bucket)
删除多个对象(启用版本的存储桶)
AmazonS3Client
class. AmazonS3Client
类的实例。 Create an instance of the DeleteObjectsRequest
class and provide a list of objects keys
and optionally the version IDs of the objects that you want to delete. 创建
DeleteObjectsRequest
类的实例,并提供list of objects keys
以及可选择要删除的对象的版本ID。
If you specify the version ID of the object that you want to delete, Amazon S3 deletes the specific object version
. 如果指定要删除的对象的版本ID,
Amazon S3 deletes the specific object version
。 If you don't specify the version ID of the object that you want to delete, Amazon S3 adds a delete marker
. 如果未指定要删除的对象的版本ID,则
Amazon S3 adds a delete marker
。 For more information, see Deleting One Object Per Request . 有关更多信息,请参阅删除每个请求一个对象 。
AmazonS3Client.deleteObjects
method. AmazonS3Client.deleteObjects
方法。 The following Java code sample demonstrates the preceding steps. 以下Java代码示例演示了上述步骤。
List<KeyVersion> keys = new ArrayList<KeyVersion>();
// Provide a list of object keys and versions.
DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(bucketName)
.withKeys(keys);
try {
DeleteObjectsResult delObjRes = s3Client.deleteObjects(multiObjectDeleteRequest);
System.out.format("Successfully deleted all the %s items.\n", delObjRes.getDeletedObjects().size());
} catch (MultiObjectDeleteException e) {
// Process exception.
}
For Multi-Object Delete (Non-Versioned Bucket) you can use this method also
对于多对象删除(非版本化存储桶),您也可以使用此方法
static void multiObjectNonVersionedDelete(List<KeyVersion> keys) {
// Multi-object delete by specifying only keys (no version ID).
DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(
bucketName).withQuiet(false);
// Create request that include only object key names.
List<KeyVersion> justKeys = new ArrayList<KeyVersion>();
for (KeyVersion key : keys) {
justKeys.add(new KeyVersion(key.getKey()));
}
multiObjectDeleteRequest.setKeys(justKeys);
// Execute DeleteObjects - Amazon S3 add delete marker for each object
// deletion. The objects no disappear from your bucket (verify).
DeleteObjectsResult delObjRes = null;
try {
delObjRes = s3Client.deleteObjects(multiObjectDeleteRequest);
System.out.format("Successfully deleted all the %s items.\n", delObjRes.getDeletedObjects().size());
} catch (MultiObjectDeleteException mode) {
printDeleteResults(mode);
}
}
For details with example, you can follow the tutorials 有关示例的详细信息,您可以按照教程进行操作
If urls is longer than keys, you will submit an array that is longer than the size of keys with null entries which will probably lead to the exception (not tried myself). 如果url比key长,你将提交一个数组,该数组的长度大于带有空条目的键的大小,这可能会导致异常(我自己没试过)。
You'll probably want: 你可能想要:
client.deleteObjects(new DeleteObjectsRequest(bucketName)
.withKeys(keys.toArray(new String[keys.length]))
--------------------------------------^^^^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.