Reputation: 772
Is there a way to retrieve the MIME types of the objects in S3. I am trying to implement a solution in which I will be getting multiple objects from S3. Instead of using there key and then getting a sub string to calculate the MIME type, can I get the MIME type from Amazon S3 in some way? I am using cloud berry explorer pro and I know it let's you set the MIME type, but how do we retrieve this information using the AWS SDK for .NET or the REST API?
Upvotes: 15
Views: 36617
Reputation: 3190
To get the file and mimeType of the file in the same request...
using (var client = AWSClientFactory.CreateAmazonS3Client(region))
{
var response = client.GetObject(bucket, key);
var mimeType = response.Headers.ContentType;
return new StreamWithMimeType(response.ResponseStream, mimeType);
}
Upvotes: 5
Reputation: 11690
The REST API offers the HEAD Object operation for this purpose and the AWS SDK for .NET conveniently wraps the very same functionality via the GetObjectMetadata() method:
The GetObjectMetadata operation is used to retrieve information about a specific object or object size, without actually fetching the object itself. This is useful if you're only interested in the object metadata, and don't want to waste bandwidth on the object data. The response is identical to the GetObject response, except that there is no response body. [emphasis mine]
Upvotes: 11