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

  • Home
  • SEARCH
  • 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 7999739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:35:22+00:00 2026-06-04T15:35:22+00:00

I am trying to retrieve some HTML files from Amazon s3 using AWS SDK

  • 0

I am trying to retrieve some HTML files from Amazon s3 using AWS SDK for .NET. I am able to get the HTML file but the images that are linked to the webpage are not being displayed neither is the relevant style sheet applied. Now, I do understand why this is happening. Because each image and style sheet is a separate object in Amazon s3 and my code is only creating presigned URL for the HTML file:

 private void GetWebUrl()
{
        var request =
                new GetPreSignedUrlRequest().WithBucketName(bucketName)
                  .WithKey("test/content.htm");
            request.WithExpires(DateTime.Now.Add(new TimeSpan(0, 0, 0, 50)));
            var url = S3.GetPreSignedURL(request);
            Iframe2.Attributes.Add("src", url);
}

What is the best way to access the images and style sheet related to this HTML file? I can look for all the images and then use the above method to generate presigned URL requests but that is not an efficient method and I can’t make the images and style sheet public. Has anyone else encountered a similar issue?
Also, is it better if I use Rest API to authenticate user( using authentication Header) so that the browser will have authentication information in header and I will not have to create presigned URL’s for each object. A small piece of code for REST API would be very helpful.

  • 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-04T15:35:24+00:00Added an answer on June 4, 2026 at 3:35 pm

    The best way to achieve this is by using Generic Handlers(.ASHX). The trick is to change the source of webpage and related objects to your handler:

    src:"StreamFile.ashx?file="ObjKey"
    

    Now, to change the source you either update your old HTML files and create new ones with source pointing to (StreamFile.ashx)Generic Handler or use URL rewrite to write old URL’s to new URL. This can be done in IIS or in the web.config.If you do it in IIS it will automatically add code in your web.config.

    <system.webServer>
        <rewrite>
          <rules>
            <rule name="Content">
              <match url="DevelopmentContent/Course/([a-zA-Z0-9]+)" />
              <action type="Rewrite" url="StreamFile.ashx/?file=course{R:1}" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    

    The above code will look for “DevelopmentContent/Course/” in Src string and if found will rewrite the URL to StreamFile.ashx/?file=course{R:1}. R:1 will the rest of the URL-bold part(DevelopmentContent/Course/xyz/xsd/x/sd/ds.htm) which should map to your object key in amazon S3.Now in StreamHandler.ashx will receive the requests from the server with specified URL. You can then get the object key from query string(context.Request.QueryString[“file”]) and then create a function to Get the required object.

    public void ProcessRequest(HttpContext context)
            {           
                var response = Gets3Response(context.Request.QueryString["file"]);
                if (response != null)
                {
                    using (response)
                    {
                        var mimEtype = response.ContentType;
                        context.Response.ContentType = mimEtype;
                        using (var responseStream = response.ResponseStream)
                        {
                            var buffer = new byte[8000];
                            var bytesRead = -1;
                            while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                context.Response.OutputStream.Write(buffer, 0, bytesRead);
                            }
                        }
                        context.Response.Flush();
                        context.Response.End();
                    }
                }
                else
                {
    
                    context.Response.Write("Unable to retrieve content!");
    
                }
            }
    
    
    
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
        private static GetObjectResponse Gets3Response(string fileName)
            {
                GetObjectResponse response;
                if (fileName.Trim().Length == 0)
                {
                    return null;
                }
                try
                {
                    var request = new GetObjectRequest();
                    request.WithBucketName(BucketName).WithKey(fileName);
                    response = AmazonS3ClientProvider.CreateS3Client().GetObject(request);
                }
                catch (AmazonS3Exception amazonS3Exception)
                {
                    if (amazonS3Exception.ErrorCode != null &&      (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                    {
                    }
                    return null;
                }
                catch (Exception ex)
                {
                    return null;
                }
    
                return response;
            }
    

    So now all the HTTP requests will be made using your server as proxy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to retrieve the text data from an ePub file using Java.
I'm trying to use jQuery.post() function to retrieve some data. But i get no
I am trying to use Regular Expressions to decode some HTML I retrieve from
I am trying to retrieve some data from a database using jQuery's $.getJSON method
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I'm trying to retrieve the SubItem in my ListView from another thread, but I
I am trying to retrieve the correct value from an ArrayList of objects (.NET
I'm trying to retrieve images from any site that has images I'm using simplehtmldom
I've been trying to retrieve a page of HTML using pycurl, so I can
I'm trying to retrieve JSON data from servlet and display in html. I was

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.