I have turned on the versioning option for my bucket. I have also uploaded a file twice to a folder in my bucket with the same name, creating two revisions of the file.
e.g. mybucket/myfile.jpg (revision 1 and revision 2 (current))
I am trying to use the AmazonS3 .NET tools to get a list of the versions for a single file as mentioned above. As I want the functionality for a user to be able to download a previous version of the uploaded file.
Here is a method that I have created, I am able to get a list of all the files in my bucket/folder. But not a specific file in the bucket/folder (I call it a folder, but is is a key / object in itself).
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();
}
I have tried a few of the available classes, however I am unable to get the version history for a single file. (Probably missing something small)
As you mentioned, you are missing a small thing. Use prefix of the ListVersionsRequest
E.g.
Kamal