// Upload entire file
        private void UploadWholeFile(HttpContext context, List<AmazonFilesStatus> statuses)
        {
            for (int i = 0; i < context.Request.Files.Count; i++) {
                var file = context.Request.Files[i];

                MemoryStream thumbStream = new MemoryStream();
                var fileExt = file.FileName.Remove(0,file.FileName.LastIndexOf('.')).ToLower();
                var needsThumb =  Regex.Match(file.FileName.ToLower(),AmazonHelper.ImgExtensions()).Success;
                var keyName = GetKeyName(context,file.FileName.ToLower());
                var len = file.ContentLength;
                var height = 0;
                var width = 0;
                if(needsThumb){

                    file.InputStream.CopyTo(thumbStream);
                }
                var client = AmazonHelper.GetS3Client();
                var request = new PutObjectRequest()
                                        .WithKey(keyName)
                                        .WithBucketName(StorageRoot)
                                        .WithContentType(file.ContentType)
                                        .WithCannedACL(S3CannedACL.PublicRead)
                                        .WithAutoCloseStream(true)
                                        .WithStorageClass(S3StorageClass.ReducedRedundancy)
                                        .WithInputStream(file.InputStream);
                if (needsThumb)
                {
                    Image img = Image.FromStream(thumbStream);
                    height = img.Height;
                    width = img.Width;
                    thumbStream.Position = 0;

                    request.AddHeader("x-amz-meta-width",width.ToString());
                    request.AddHeader("x-amz-meta-height",height.ToString());
                    var orientation = width > height ? "h" : "v";
                    request.AddHeader("x-amz-meta-orient",orientation);

                }

                var response = client.PutObject((PutObjectRequest)request);
                response.Dispose();
                if(needsThumb){

                    var thumbKeyName = VirtualPathUtility.RemoveTrailingSlash(keyName.Replace(file.FileName.ToLower(),"")) + "/thumbs/" + file.FileName.ToLower().Replace(fileExt,".png");
                    var thumbImageStream = GetThumbnail(thumbStream);
                    var thumbrequest = new PutObjectRequest()
                                            .WithKey(thumbKeyName)
                                            .WithBucketName(StorageRoot)
                                            .WithContentType("image/png")
                                            .WithCannedACL(S3CannedACL.PublicRead)
                                            .WithAutoCloseStream(true)
                                            .WithStorageClass(S3StorageClass.ReducedRedundancy)
                                            .WithInputStream(thumbImageStream);

                    var thumbresponse = client.PutObject((PutObjectRequest)thumbrequest);
                    thumbStream.Dispose();
                }
                var fileStatus = new AmazonFilesStatus(file.FileName.ToLower(),StorageRoot,GetPrefix(context),len,height,width );

                //string fullName = Path.GetFileName(file.FileName);
                statuses.Add(fileStatus);
            }
        }
        private void ListCurrentFiles(HttpContext context)
        {
            var bucket = ConfigurationManager.AppSettings["Assets_Amazon_Bucket"];

            var prefix = GetPrefix(context);
            var doctype = context.Request["doctype"];
            var files = new List<AmazonFilesStatus>();
            var client = AmazonHelper.GetS3Client();
            var request = new ListObjectsRequest().WithBucketName(bucket).WithDelimiter("/").WithPrefix(prefix);

            var l = client.ListObjects(request);
            foreach (var fl in l.S3Objects)
            {

                if(fl.Size > 0)
                {
                    if(String.IsNullOrWhiteSpace(doctype) || (doctype == getDocType(fl.Key)))
                    {
                        var fs = new AmazonFilesStatus(fl,bucket,prefix);
                        files.Add(fs);
                    }
                }

            }
            var typeObj = new Dictionary<String,String>();
            typeObj.Add("doc",AmazonHelper.DocExtensions());
            typeObj.Add("image",AmazonHelper.ImgExtensions());
            typeObj.Add("media",AmazonHelper.MediaExtensions());
            var retObj = new FileReturn(){Files = files,AssetTypes = typeObj};

            string jsonObj = js.Serialize(retObj);
            context.Response.AddHeader("Content-Disposition", "inline, filename=\"files.json\"");
            context.Response.Write(jsonObj);
            context.Response.ContentType = "application/json";
        }