Click here to Skip to main content
15,896,493 members
Articles / Programming Languages / XML

7 Easy Steps to Building Your Idea Around Amazon Web Services

Rate me:
Please Sign up or sign in to vote.
4.80/5 (13 votes)
18 Oct 2006CPOL11 min read 62.3K   383   55  
This article is a simple, step-by-step guide for those who have ideas and want to quickly implement them. We’ll use code to demonstrate how easy it is to build an application on Amazon S3. We’ll also highlight questions that you may ask before releasing an application.
// This software code is made available "AS IS" without warranties of any        
// kind.  You may copy, display, modify and redistribute the software            
// code either by itself or as incorporated into your code; provided that        
// you do not remove any proprietary notices.  Your use of this software         
// code is at your own risk and you waive any claim against Amazon               
// Digital Services, Inc. or its affiliates with respect to your use of          
// this software code. (c) 2006 Amazon Digital Services, Inc. or its             
// affiliates.          


using System;
using System.Collections;
using System.Net;
using System.IO;
using System.Text;

namespace com.amazon.s3.rest
{
    public class GetResponse : Response
    {
        private S3Object obj;
        public S3Object Object {
            get {
                return obj;
            }
        }

        public GetResponse( WebRequest request ) :
            base(request)
        {
            SortedList metadata = extractMetadata( response );
            string body = Utils.slurpInputStream( response.GetResponseStream() );

            UTF8Encoding encoding = new UTF8Encoding();
            byte[] bytes = encoding.GetBytes(body);
            this.obj = new S3Object( bytes, metadata);
        }

        private static SortedList extractMetadata( WebResponse response )
        {
            SortedList metadata = new SortedList();
            foreach ( string key in response.Headers.Keys ) {
                if ( key == null ) continue;
                if ( key.StartsWith( Utils.METADATA_PREFIX ) ) {
                    metadata.Add( key.Substring( Utils.METADATA_PREFIX.Length ), response.Headers[ key ] );
                }
            }
            return metadata;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions