• 前台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("无文件!");
            }

  • 相关阅读:
    beanshell-接口返回结果与预期结果比较(预期结果为两个接口差集)-两个set集合的比较
    jmeter断言之Beanshell断言(判断数据库结果是否符合预期)
    beanshell查询结果多条取满足条件的一条数据作为前置步骤给其他接口参数使用
    beanshell判断响应数据是jsonobject类型还是jsonarray类型
    yarn global add安装的目录(window10)
    React 使用axios,将axios注入到全局使用
    解决H5支付宝支付空白页问题
    React Ant Design Mobile ListView 上拉刷新,下拉加载
    vue点击实现复制
    element 设置table表头样式
  • 原文地址:https://www.cnblogs.com/nxj1997/p/13224694.html
Copyright © 2020-2023  润新知