private void Delete()
        {
            string file_name = null;

            if (Request["file"] != null)
            {
                file_name = Request["file"];
            }
            string file_path = upload_handler.upload_dir + file_name;

            UploadHandler.UploadFileInfo file = upload_handler.FileObjectGet(file_name);

            bool success = File.Exists(file_path) && file_name.Length > 0 && file_name.Substring(0, 1) != ".";

            if (success)
            {
                success = false;
                File.Delete(file_path);
                success = true;
            }
            if (success)
            {
                //Delete other file versions.
                foreach (string version in file.image_versions.Keys)
                {
                    if (File.Exists(file.image_versions[version].dir + file_name))
                    {
                        File.Delete(file.image_versions[version].dir + file_name);
                    }
                }
            }
            Response.AddHeader("Content-type", "application/json");
            Response.Write(Json.Serialize <bool>(success));
            Response.End();
        }
        private void Post()
        {
            if (Request["_method"] != null && Request["_method"] == "DELETE")
            {
                Delete();
            }

            List <UploadHandler.UploadFileInfo> fileInfoList = new List <UploadHandler.UploadFileInfo>();
            HttpFileCollection upload = Request.Files;

            for (int i = 0; i < upload.Count; i++)
            {
                UploadHandler.UploadFileInfo fileInfo = new UploadHandler.UploadFileInfo();
                HttpPostedFile file = upload[i];
                fileInfo.type = Path.GetExtension(file.FileName).ToLower();
                fileInfo.name = Path.GetFileName(file.FileName);
                fileInfo.size = file.InputStream.Length;
                if (Request.Headers["X-File-Size"] != null)
                {
                    fileInfo.size = long.Parse(Request.Headers["X-File-Size"].ToString());
                }

                fileInfo = upload_handler.FileUploadHandle(file, fileInfo.name, fileInfo.size, fileInfo.type, fileInfo.error, i);
                fileInfoList.Add(fileInfo);
            }
            Response.Clear();
            Response.AddHeader("Vary", "Accept");
            string json     = Json.Serialize <List <UploadHandler.UploadFileInfo> >(fileInfoList);
            string redirect = null;

            if (Request["redirect"] != null)
            {
                redirect = Request["Redirect"];
            }
            if (redirect != null)
            {
                Response.AddHeader("Location", String.Format(redirect, Server.UrlEncode(json)));
                Response.StatusCode = 302;
                Response.End();
            }
            if (Request.ServerVariables["HTTP_ACCEPT"] != null && Request.ServerVariables["HTTP_ACCEPT"].ToString().IndexOf("application/json") >= 0)
            {
                Response.AddHeader("Content-type", "application/json");
            }
            else
            {
                Response.AddHeader("Content-type", "text/plain");
            }

            Response.Write(json);
            Response.End();
        }