简体   繁体   English

无法使用.Net API读取Amazon S3 Object元数据,我做错了什么?

[英]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.

相关问题 JSON.NET的JsonConvert我在做什么错 - What am I doing wrong with JSON.NET's JsonConvert 无法获得嵌套的IF在C#中正常工作。 我究竟做错了什么? - Can't get nested IF's to work properly in C#. What am I doing wrong? 我在用IQueryable做错什么 <T> ? - What am I Doing Wrong with IQueryable<T>? 我正在使用 Alpha Vantage API 来尝试获取每日库存信息。 我对使用 API 真的很陌生,不知道我做错了什么 - I am using Alpha Vantage API to try and pull daily stock info. I am really new to using APIs and don't know what I am doing wrong 我正在统一使用Raycast,当我单击它时我想获取对象的位置,但是我不工作并且我不知道我在做什么错 - I am using Raycast in unity and i want to get the position of an object when i click on it but i does not work and i don't know what i am doing wrong 我做错了什么,所以数据绑定目标不会受到数据绑定源的影响 - What am I doing wrong so the data binding target doesn't get affected by data binding source 我做错了什么? 尝试从API获得响应 - What I am doing wrong? Trying to get response from the API Bing-Map-API我在做什么错? - Bing-Map-API what am I doing wrong? 此C#.NET WinForms应用程序在做什么? - What am I doing wrong with this C# .NET WinForms application? .NET正则表达式负提前-我在做什么错? - .NET Regex Negative Lookahead - what am I doing wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM