开发者

Enabling versioning in Amazon S3 bucket

I am trying to enable versioning for Amazon S3 bucket using Java. But, I am not able to do. I get an exception

"Exception Status Code: 400, AWS Request ID: DC53C8220CEC7D4C, AWS Error Code: MalformedXML, AWS Error Message: The XML you provided was not well-开发者_如何转开发formed or did not validate against our published schema, S3 Extended Request ID: qAdibjSkoFltjoYTFZSdTOnh8JXwZrxkjgrTcgaXqZYGIgVdbRxr8VXzwkO4ilaG"

Can somebody please point out the error in the code. I am attaching the portion of the code responsible for enabling bucket versioning.

public void enableVersioning(String bucketName) {
    SetBucketVersioningConfigurationRequest request = 
        new SetBucketVersioningConfigurationRequest(bucketName, 
        new BucketVersioningConfiguration("ENABLED"));
    AmazonS3 s3 = new AmazonS3Client(credentials);   // I have the credentials
    s3.setBucketVersioningConfiguration(request); 
}

Thanks in advance.


They should be the same, but I would use BucketVersioningConfiguration.ENABLED instead of the String literal if I were you. Do an import static if you think it clutters up the code too much. (Who knows, it might even mysteriously fix your problem)

Just did pretty much exactly this myself and it worked, this was the only difference I could find.


OhHiThere is correct - you should be using the LITERAL:

SetBucketVersioningConfigurationRequest request = 
    new SetBucketVersioningConfigurationRequest(bucketName, 
    new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED));

The error is almost certainly because "ENABLED" is not the same as BucketVersioningConfiguration.ENABLED (which is defined as "Enabled").

I have also seen this error:

The XML you provided was not well-formed

message trying to turn versioning off when it has been on (only a suspend is allowed in that case).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜