简体   繁体   English

在ashx处理程序中使用uploadify

[英]Using uploadify with ashx handler

Hi friends i have a form in which there are some text boxes, drop downs and as well as image . 嗨,朋友们,我有一种形式,其中有一些文本框,下拉列表以及图像。 I am using knock out js to save the form details. 我正在使用敲除js保存表单详细信息。 And i am using uploadify plugin to upload my image to a local folder .I have implemented all this things but when it comes to saving the values till now i used a aspx code behind . 而且我正在使用uploadify插件将图像上传到本地文件夹。我已经实现了所有这些操作,但是在保存值之前,直到现在我都使用了aspx代码。 For uploading purpose we had to choose ashx. 为了上传,我们必须选择ashx。 So it will be like two server side postings going to happen!! 因此,就像发生两个服务器端发布一样!!

So i would like to save my data in ashx page rather than aspx. 所以我想将数据保存在ashx页面而不是aspx中。

But i am confused where exactly to start my upload..please some one help me with this!!! 但是我很困惑从哪里开始我的上传..请有人帮助我!!!

i am saving my values in a save button event like below!! 我将我的值保存在如下所示的保存按钮事件中!

     self.AddEvent = function (args) {          

       // Here--> $('#file_upload').uploadify('upload');

                    ajax.Post("../Scripts/uploadify/UploadHandler.ashx", JSON.stringify({ objEnt: args }), false).success(function (data) {   

                    if (data.d[0] > 0) {
        // or Here-->            $('#file_upload').uploadify('upload');
                    alert('success');
                  }

and my fileupload setting s are: 和我的fileupload设置是:

   $('#file_upload').uploadify({
                'swf': '../Scripts/uploadify/uploadify.swf',
                'uploader': '../Scripts/uploadify/UploadHandler.ashx',
                'method': 'post',
                'formData': { 'someKey': Filename },
                'buttonText': 'Browse',
                'auto': false,
                'folder': 'upload',

                'fileTypeExts': '*.jpg;*.jpeg;*.gif;*.png',
                'onSelect': function (file) {
                    var ext = file.name.split('.').pop();
                    $("#filename").val(Filename + '.' + ext);
                },
                'onUploadSuccess': function (file, data, response) {

                    if (response == true) {

                       $("#eventGrid").jqxGrid('updatebounddata');



                    }

                }

            });

It is not possible to call self.AddEvent in 'onUploadsuccess' in my situation...!!! 在我的情况下,无法在“ onUploadsuccess”中调用self.AddEvent ... !!! Please suggest me some best way to store my data and image at same time in ashx handler. 请建议我一些最好的方式同时在ashx处理程序中存储数据和图像。

ashx: ashx:

  public void ProcessRequest(HttpContext context)
{

    context.Response.ContentType = "application/json";
    var data = context.Request;
    var sr = new StreamReader(data.InputStream);
    var stream = sr.ReadToEnd();
    var javaScriptSerializer = new JavaScriptSerializer();
    var asd = javaScriptSerializer.Deserialize<RootObject>(stream);
    string Newname = context.Request.Form["someKey"];
    BAL Bl = new BAL();

    string[] args = new string[2];
   //AddEvent method will add my data into database add return response "Success"//
    args = AddEvent(asd.objEnt);

        HttpPostedFile PostedFile = context.Request.Files["Filedata"];

            string ext = Path.GetExtension(PostedFile.FileName);
            string savepath = "";
            string temppath = "";
            temppath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
            savepath = context.Server.MapPath(temppath);
            string fileName = Newname + ext;
            if (!Directory.Exists(savepath))
                Directory.CreateDirectory(savepath);

            PostedFile.SaveAs(savepath + @"\" + fileName);

            context.Response.Write(temppath + "/" + fileName);
           // context.Response.Write(args);

            context.Response.StatusCode = 200;

        }
    }
 $("#<%=FileUpload1.ClientID%>").uploadify({
            'uploader': 'Upload.ashx',
            'swf': 'uploadify/uploadify.swf',
            'script': 'Upload.ashx',
            'cancelImg': 'images/cancel.png',
            'folder': '../Upload',
            'multi': true,
            'buttonText': 'select picture',
            'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg',
            'auto': false,
            'onUploadStart': function () {


            }
        });


$.ajax({
            type: "POST",
            url: 'WebServiceAdmin.asmx/SaveData',
            data: "{'p':'" + datam+ "'}",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (d) { $('#FileUpload1').uploadify('upload', '*');  },
            error: function () {  }
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM