[英]Can't read Amazon S3 Object meta-data using .Net API, what am I doing wrong?
I've read the S3 documentation several times and I'm adding metadata to an S3 object with this code... 我已多次阅读S3文档,并且我正在使用此代码向S3对象添加元数据......
PutObjectRequest titledRequest = new PutObjectRequest();
titledRequest.WithTimeout(3600000)
.WithMetaData("outputfolder", outputFolder)
.WithBucketName(AWS_BUCKET_NAME)
.WithKey(objectKey)
.WithAutoCloseStream(true)
.WithInputStream(fs);
When reading the object from the S3 bucket I'm using this code.... 从S3存储桶读取对象时我正在使用此代码....
string outputFolder = response.Metadata["x-amz-meta-outputfolder"];
But I'm getting an empty string every time even though the outputFolder variable definitely has a value. 但是我每次都得到一个空字符串,即使outputFolder变量肯定有一个值。
Am I doing something really silly wrong here? 我在这里做了一些非常愚蠢的错事吗? As far as I can tell this is consistent with the documentation
据我所知,这与文档一致
string outputFolder = response.Metadata["outputfolder"];
会做。
Codes verified to work. 验证的代码有效。
// upload & add outputfolder to metadata
var S3Client = new AmazonS3Client();
var Request = new PutObjectRequest {
BucketName = bucketname,Key = S3Name,FilePath = Filepath };
Request.Metadata.Add("outputfolder",@"C:\test");
PutObjectResponse Response = S3Client.PutObject(Request);
// download and retrieve metadata
var S3Client = new AmazonS3Client();
var Request = new GetObjectRequest { BucketName = bucketname,Key = S3Name };
GetObjectResponse Response = S3Client.GetObject(Request);
// this works
string outputFolder = Response.Metadata["x-amz-meta-outputfolder"];
// so does this - no need for the x-amz-meta- prefix
string outputFolder = Response.Metadata["outputfolder"];
use this instead of reading the meta from putobject response 使用它而不是从putobject响应中读取元数据
GetObjectMetadataRequest request = new GetObjectMetadataRequest()
.WithKey("Key")
.WithBucketName("");
GetObjectMetadataResponse response = s3Client.GetObjectMetaData(request);
response."choose properety to retrieve"
hope this may help 希望这可能有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.