我正在开发一个将文件上传到s3存储桶的应用程序,我想使用适用于.net的aws sdk列出对象及其上传日期。 有没有执行此操作的代码?
答案 0 :(得分:2)
UPD::不幸的是,S3不存储对象的上传日期。它可以为您提供lastModifiedDate,仅当上传后未修改对象时才等于“上传日期”。
为了获取上传日期,您应该在上传期间使用以下对象将其保存:
var putRequest = new PutObjectRequest
{
BucketName = bucketName,
Key = keyName,
FilePath = filePath,
ContentType = "text/plain"
};
putRequest.Metadata.Add("x-upload-date", "someUploadDate");
然后从对象元数据中读取它
GetObjectRequest request = new GetObjectRequest
{
BucketName = bucketName,
Key = keyName
};
using (GetObjectResponse response = await client.GetObjectAsync(request))
using (Stream responseStream = response.ResponseStream)
using (StreamReader reader = new StreamReader(responseStream))
{
string uploadDate = response.Metadata["x-upload-date"];
}