How can I set the S3 bucket file header to be the following:
content-encoding: gzip content-type: text/css
I am using Amazon API using the SDK for .NET. I am uploading a file to S3 using the PutObjectRequest. The problem that when the file is uploaded, the content type and content encoding headers aren't beign updated (I've checked via the files properties on Amazon Console).
example:
request.AddHeader("expires", EXPIRES_DATE);
request.AddHeader("content-encoding", "gzip");
request.ContentType = "text/css";
Also tried:
NameValueCollection metadata = new NameValueCollection();
metadata.Add("content-type", "text/css");
metadata.Add("content-encoding", "gzip");
request.WithMetaData(metadata);
What I'm doing wrong?
Content encoding allows API clients to request content to be compressed before being sent back in the response to an API request. This reduces the amount of data that is sent from API Gateway to API clients and decreases the time it takes to transfer the data. You can enable content encoding in the API definition.
Amazon API Gateway is an AWS service for creating, publishing, maintaining, monitoring, and securing REST, HTTP, and WebSocket APIs at any scale. API developers can create APIs that access AWS or other web services, as well as data stored in the AWS Cloud .
The accepted answer was right at the time but the API updated in 2014 so this is the new way
PutObjectRequest request = new PutObjectRequest
{
BucketName = bucketName,
ContentType = "text/css",
Key = filename
};
request.Headers["Content-Encoding"] = "gzip";
In 2019 using the latest API the code will look like this:
PutObjectRequest request = new PutObjectRequest {
BucketName = bucketName,
ContentType = "text/css",
Key = filename
};
request.Headers.ContentEncoding = "gzip";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With