我有代码写入s3存储桶的内容。
PutObjectRequest titledRequest = new PutObjectRequest();
titledRequest.WithMetaData("Eip1", "Volume-1")
.WithMetaData("Eip2", "Volume-2")
.WithContentBody("this is an Elastic IP Address Details for a Volumes")
.WithBucketName(bucketName)
.WithKey(keyName);
并使用
阅读 AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID);
GetObjectRequest request = new GetObjectRequest().WithBucketName(bucketName).WithKey(keyName);
string title = response.Metadata.Get("Eip1");
但是得到null作为回报,在调试时我看到response.Metadata.Keys有
的x AMZ - 间 - eip1
&安培; x-amz-meta-eip2
如何重命名此键,如何避免这种情况?
为什么它们以 x-amz-meta -
作为前缀答案 0 :(得分:2)
它们以这种方式设计为“将它们区分为自定义HTTP标头”
http://docs.amazonwebservices.com/AmazonS3/latest/index.html?UsingMetadata.html
答案 1 :(得分:1)
如果您使用.WithMetadata,则s3客户端始终使用x-amz-meta作为元数据的前缀。如果要指定系统元数据(如缓存控制标头),请在请求中使用.AddHeaders:
var rq = (PutObjectRequest) new PutObjectRequest()
.WithKey(fileName)
.WithBucketName(BucketName)
.WithCannedACL(S3CannedACL.PublicRead)
.WithInputStream(source);
rq.AddHeaders(new WebHeaderCollection
{
{HttpRequestHeader.CacheControl, "no-cache"}
});