Search code examples
c#asp.netamazon-s3http-headers

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?


Solution

  • 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