Pergunta

I am uploading my pictures using uplodifiy. here is the my codes are below.but inside the Upload.ashx handler,I coulnt get the submitted values(Id and foo values).they return null values. how can I solve this problem .thank you . I have a code like this

  $(document).ready(function () {

        var id = "55";
        var theString = "asdf";

        $("#<%=FileUpload1.ClientID%>").uploadify({
            'uploader': 'Upload.ashx',
            'swf': 'uploadify/uploadify.swf',
            'script': 'Upload.ashx',
            'cancelImg': 'images/cancel.png',
            'folder': 'upload',
            'multi': true,
            'buttonText': 'RESIM SEC',
            'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg',
            'auto': false,
            'scriptData': { 'id': id, 'foo': theString}
            ,onAllComplete: function (event, data) {

            }

        });
    });

and my ashx file like this;

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.Expires = -1;
        try
        {

    //I tryed both way to get values both both return null values.
            string pwd1 = context.Request["Id"];
            string pwd2 = context.Request.Form["Foo"];



            HttpPostedFile postedFile = context.Request.Files["Filedata"];
            string id = context.Request["id"];
            string savepath = "";
            string tempPath = "";

            tempPath = context.Request["folder"];

            //If you prefer to use web.config for folder path, uncomment below line:
            //tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"]; 


            savepath = context.Server.MapPath(tempPath);
            string filename = postedFile.FileName;
            if (!Directory.Exists(savepath))
                Directory.CreateDirectory(savepath);
            string ext = System.IO.Path.GetExtension(filename);
            string resimGuid = Guid.NewGuid().ToString();
..........
..........
Foi útil?

Solução

Use formData with Post method

Extra data can be passed to the script as either a querystring if the method option is set to ‘get’, or via the headers if it’s set to ‘post’. This is all done with the help of the formData option. Depending on what you’ve set as the method option (‘post’ or ‘get’), you can retrieve the information sent in the formData option at server side.

For more detils Please refer Passing Extra Data

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top