2015-05-29 59 views
2

我想要一套新的標記添加到使用AWS的Java API的S3桶,但我得到象這樣的錯誤時:MalformedXML標記的S3存儲

com.amazonaws.services.s3.model.AmazonS3Exception: The XML you provided was not well-formed or did not validate against our published schema (Service: Amazon S3; Status Code: 400; Error Code: MalformedXML; Request ID: 5B3401CBDB133A88), S3 Extended Request ID: z1EDhMH5vN7o/9Tk93K5R1gWmmqUr49WjEz2rovD9HRCGJ54yHBfoTuUURvnpoizlCUK3Fy9qbY= 

這是代碼我已經寫了(newTagsMap<String, String>):

List<TagSet> tags = amazonS3.getBucketTaggingConfiguration(bucketName).getAllTagSets(); 
tags.add(new TagSet(newTags)); 
s3Service.setBucketTaggingConfiguration(bucketName, new BucketTaggingConfiguration(tags)); 

我還沒有使用XML自己,錯誤是無益的,什麼是實際發生錯誤。發生什麼事?

回答

2

Java API和REST API之間存在小的不匹配。看看PUT Bucket Tag request。沒有明確說明,但這意味着每Tagging集合只能有一個TagSet。然而,BucketTaggingConfiguration允許TagSets的列表。

不是添加一個新的TagSet,而是從配置中的第一個TagSet獲取Map<String, String>,將標籤添加到該映射中,然後從中創建一個新的TagSet。對待BucketTaggingConfiguration,就像它只允許TagSets的單個項目列表一樣。

1

好的,終於明白了這一點,但這裏是我的代碼,我如何獲得多個標記放置在S3存儲桶上。雖然代碼暗示我可以添加多個tagSets,但如果我這樣做,它似乎會失敗並出現上述錯誤。我剛剛創建了一個帶有mu的TagSet

public void TagS3(String bucketName, Map<String,String> tags){ 


    if(0 < tags.size()){ 
     TagSet ts = new TagSet(tags); 
     BucketTaggingConfiguration btconfig = new BucketTaggingConfiguration(); 
     btconfig.withTagSets(ts); 
     SetBucketTaggingConfigurationRequest tgRq = new SetBucketTaggingConfigurationRequest(bucketName, btconfig); 
     s3client.setBucketTaggingConfiguration(tgRq); 
    } 

}