gpt4 book ai didi

object - Amazon S3 获取上传文件的版本列表

转载 作者:行者123 更新时间:2023-12-02 04:49:33 24 4
gpt4 key购买 nike

我已为我的存储桶打开版本控制选项。我还两次将文件上传到存储桶中同名的文件夹中,从而创建了该文件的两个修订版。

例如mybucket/myfile.jpg(修订版 1 和修订版 2(当前))

我正在尝试使用 AmazonS3 .NET 工具来获取如上所述的单个文件的版本列表。因为我希望用户能够下载上传文件的先前版本。

这是我创建的一个方法,我能够获取我的存储桶/文件夹中所有文件的列表。但不是存储桶/文件夹中的特定文件(我称其为文件夹,但它本身就是一个键/对象)。

public String AmazonS3GetObjectVersions(Guid DocumentId)
{
AmazonS3 s3Client = AmazonS3ClientConnection();

GetObjectMetadataRequest ORequest = new GetObjectMetadataRequest();
ORequest.BucketName = DocumentStorageFolder(DocumentId); // e.g. mybucket
ORequest.Key = DocumentStorageReference(DocumentId); // e.g. myfolder/myfile.jpg

GetObjectMetadataResponse OResponse = s3Client.GetObjectMetadata(ORequest);

S3ObjectVersion version = new S3ObjectVersion();
version.BucketName = DocumentStorageFolder(DocumentId);
version.Key = DocumentStorageReference(DocumentId);
version.IsDeleteMarker = false;

ListVersionsRequest Request = new ListVersionsRequest();
Request.BucketName = DocumentStorageFolder(DocumentId);

String tmp = DocumentStorageReference(DocumentId);

string[] tmparr = tmp.Split('/');

Request.KeyMarker = tmparr[0];
//Request.Delimiter = "/";
//Request.MaxKeys = int.Parse(appConfig["MAX_VERSIONS"]);

ListVersionsResponse Response = s3Client.ListVersions(Request);

//Response.NextKeyMarker = tmparr[1];

Response.KeyMarker = tmparr[1];

List<S3ObjectVersion> Versions = new List<S3ObjectVersion>();

Versions = Response.Versions;

return Versions.ToString();
}

我尝试了一些可用的类,但是我无法获取单个文件的版本历史记录。 (可能遗漏了一些小东西)

最佳答案

正如您提到的,您错过了一件小事。使用 ListVersionsRequest 的前缀

例如

ListVersionsRequest Request = new ListVersionsRequest();
Request.BucketName = DocumentStorageFolder(DocumentId);
Request.Prefix = KeyName

卡迈勒

关于object - Amazon S3 获取上传文件的版本列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5843445/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com