繁体   English   中英

在ashx处理程序中使用uploadify

[英]Using uploadify with ashx handler

嗨,朋友们,我有一种形式,其中有一些文本框,下拉列表以及图像。 我正在使用敲除js保存表单详细信息。 而且我正在使用uploadify插件将图像上传到本地文件夹。我已经实现了所有这些操作,但是在保存值之前,直到现在我都使用了aspx代码。 为了上传,我们必须选择ashx。 因此,就像发生两个服务器端发布一样!!

所以我想将数据保存在ashx页面而不是aspx中。

但是我很困惑从哪里开始我的上传..请有人帮助我!!!

我将我的值保存在如下所示的保存按钮事件中!

     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');
                  }

和我的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');



                    }

                }

            });

在我的情况下,无法在“ onUploadsuccess”中调用self.AddEvent ... !!! 请建议我一些最好的方式同时在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