• 前台form-data格式 上传文件


     public HttpResponseMessage UpLoad()
            {
                // "请求内容不是表单形式";
                if (!Request.Content.IsMimeMultipartContent("form-data"))
                {
                    var json = PostModel("请求内容不是表单形式");
                    return json;
                }
                if (HttpContext.Current.Request.Files.Count > 0)
                {
                    Log log = new Log(AppDomain.CurrentDomain.BaseDirectory + @"/log/Log.txt");
                    try
                    {                
                        var file = HttpContext.Current.Request.Files[0];//获取文件
                        //获取前端from-data表单形式中的参数
                        HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context
                        HttpRequestBase request = context.Request;//定义传统request对象                  
                        string fname = file.FileName;//获取文件名称
                        string SavePath = HttpContext.Current.Server.MapPath(string.Format("~/{0}", "合同附件"));
                        if (!Directory.Exists(SavePath))
                        {
                            Directory.CreateDirectory(SavePath);
                        }
                        string fullPathUrl = Path.Combine(SavePath, fname);
                        file.SaveAs(fullPathUrl);
                        #region 赋值
                        Appendix app = new Appendix();
                        app.value = 1;
                        app.file_url = fullPathUrl;
                        app.file_name = fname;
                        app.cid = Convert.ToInt32(request.Form["cid"]);
                        #endregion
                        VMAppendix vM = new VMAppendix();
                        //添加文件
                        var result = vM.CUDAppendix(app);
                        var json = PostModel(result);
                        return json;
                    }
                    catch (Exception ex)
                    {
                        log.log(" 错误提示:" + ex.ToString());
                        throw ex;
                    }
                }
                return PostModel("无文件!");
            }

  • 相关阅读:
    sqlmap参数设置
    SQL注入
    SQL注入基本原理
    信息收集(shodan的使用)
    CDN
    2020软件工程个人作业06——软件工程实践总结作业
    问题清单
    2020软件工程作业05
    2020软件工程作业00——问题清单
    软件工程第三次作业
  • 原文地址:https://www.cnblogs.com/nxj1997/p/13224694.html
Copyright © 2020-2023  润新知