Setting content-encoding and content-type with Amazon API for .NET

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?

you add the content-type to the contentType property in the api like the following

 PutObjectRequest request = new PutObjectRequest();
    string contentType = "text/css";
    request = request.WithContentType(contentType); 

//for the content-encoding //add the following header

request.AddHeader("content-encoding","gzip");

hope this could help

c#, 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. Setting up tags for an API stage in API Gateway Setting up stage variables for a REST API deployment Javascript is disabled or is unavailable in your browser.

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";

Content type conversions in API Gateway, Convert content types in API Gateway. Text data, A text data type, Set with matching media types, CONVERT_TO_TEXT, Text data. Binary data, A binary data� The Content-Encoding entity header is used to compress the media-type. When present, its value indicates which encodings were applied to the entity-body. It lets the client know how to decode in order to obtain the media-type referenced by the Content-Type header.

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";

Enabling payload compression for an API, API Gateway allows your client to call your API with compressed payloads by using one of the supported content codings. By default, API Gateway supports� Content type conversions in API Gateway; Content encoding. To help you get started using Amazon API Gateway, go through the following hands-on walkthroughs

AWS Developer Forums: "Content-Encoding: utf-8" , "Content-Encoding: utf-8" header causes 500 from API Gateway "Via: 1.1 437acf5020e44b923e28b10f7fccb788.cloudfront.net encoding (not a content encoding), setting UTF-8 encoding is done in the Content-Type� The Content-Type entity header is used to indicate the media type of the resource. In responses, a Content-Type header tells the client what the content type of the returned content actually is. Browsers will do MIME sniffing in some cases and will not necessarily follow the value of this header; to prevent this behavior, the header X-Content

Receive an API response with a compressed payload, The minimumCompressionSize is set on the API to enable compression. The integration response doesn't have a Content-Encoding header. The size of an� Content Encoding Property Definition. Namespace: System.Web Assembly: System.Web.dll. In this article. Gets or sets the HTTP character set of the output stream.

Amazon API Gateway Supports Content Encoding for API Responses, To get started, create or update your API settings using the AWS Management Console, AWS CLI, or SDKs and APIs. Visit our documentation to� I was reviewing some control and handler code in my wwHoverPanel control's AJAX callback handler code. There are a number of routines that generate JavaScript output from JSON to returning resources and I noticed that the content type headers would often vary slightly. When returning a content type

Comments
  • This should be the accepted answer now. Current accepted answer is obsolete