Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7969385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:13:45+00:00 2026-06-04T07:13:45+00:00

I need to retrieve images from S3. I can’t make the folder public and

  • 0

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:

 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();
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:13:46+00:00Added an answer on June 4, 2026 at 7:13 am

    There are a couple of problems here:

    1. You are setting the Content-Type on the response coming back from amazon, but not on the response from your application
    2. You are using a StreamReader to read the content of the stream as text and then writing it back as text

    Try this instead:

    using (var response = S3.GetObject(request))
    {
        using (var responseStream = response.ResponseStream)
        {
            context.Response.ContentType = "image/jpeg";
    
            var buffer = new byte[8000];
            int bytesRead = -1;
            while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                context.Response.OutputStream.Write(buffer, 0, bytesRead);
            }
        }
    }
    
    context.Response.End();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new in C/C++ and I need to retrieve images from a shared folder
I'm working on an app that can retrieve images from the web. Rather than
I need to retrieve random rows from SQL Server database. I am looking for
I need to retrieve the date from a UIDatePicker (Preferably I would also like
I need to retrieve multiple objects from an external system. The external system supports
I need to retrieve data from two tables. the first is a list of
I need to retrieve a regex pattern matched strings from the given input. Lets
How to upload and retrieve images to and from MySql database using PHP. I
I need to get images from Google Chart, but I'm behind a proxy. With
In my app I am rendering a Video generated from images I retrieve from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.