How can I get MIME object types in Amazon S3?

Is there a way to get the MIME types of objects in S3. I am trying to implement a solution in which I will get several objects from S3. Instead of using a key there and then getting a substring to calculate the MIME type, can I get the MIME type from Amazon S3 in some way? I use cloud berry explorer pro and I know that it allows you to set the MIME type, but how can we get this information using the AWS SDK for .NET or the REST API?

+3
source share
2 answers

The REST API offers a HEAD Object for this purpose and the AWS SDK for .NET conveniently combines the same functions using the GetObjectMetadata () method :

The GetObjectMetadata operation is used to retrieve information about a specific object or object size, without actually receiving the object itself. This is useful if you are only interested in metadata and don’t want to waste bandwidth on object data. The answer is identical to the GetObject answer, except that there is no response body. [emphasis mine]

+6
source

To get the file and mimeType of the file in one request ...

using (var client = AWSClientFactory.CreateAmazonS3Client(region))
{
    var response = client.GetObject(bucket, key);
    var mimeType = response.Headers.ContentType;
    return new StreamWithMimeType(response.ResponseStream, mimeType); 
}
+2
source

All Articles