title: Getting Images from S3
body: <p>I need to retrieve images from S3. I can't make the folder public and I cant use presigned URL's so all I am left with is GetObject();. Now the image that I'll get back has to be set as a source for an Iframe. To do that I am using a HttpWebHandler. The issue is that if i retrieve a html page it is working fine. But when I try to get an image back, all i get is junk data. Here is my code:</p>
  
  <pre><code> public void ProcessRequest(HttpContext context)
          {
  
              NameValueCollection appConfig = ConfigurationManager.AppSettings;
              _accessKeyId = appConfig["AWSAccessKey"];
              _secretAccessKeyId = appConfig["AWSSecretKey"];
              S3 = new AmazonS3Client(_accessKeyId, _secretAccessKeyId);
              string responseBody = "";
              var request = new GetObjectRequest()
              .WithBucketName(bucketName).WithKey("020/images/intro.jpg");
              var responseHeaders = new ResponseHeaderOverrides
                                        {
                                            ContentType = "image/jpeg"
                                        };
  
              request.ResponseHeaderOverrides = responseHeaders;
              using (var response = S3.GetObject(request))
              {
                  using (var responseStream = response.ResponseStream)
                  {
                      using (var reader =
                          new StreamReader(responseStream))
                      {
                          responseBody = reader.ReadToEnd();
                      }
                  }
  
              }
              context.Response.Write(responseBody);
              context.Response.Flush();
              context.Response.End();
          }
  }
  </code></pre>