zoukankan      html  css  js  c++  java
  • ASP.NET Web API相关

    接收移动端上传的图片,示例代码: 

            [HttpPost]
            [ApiSecurityFilter]
            public IHttpActionResult UploadImg()
            {
                string imgs = "";
                try
                {
                    System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
                    foreach (string key in files.AllKeys)
                    {
                        System.Web.HttpPostedFile file = files[key];
                        if (!String.IsNullOrEmpty(file.FileName))
                        {
                            string filePath = "/Upload/Images/" +DateTime.Now.ToString("yyyyMM") + "/";
                            string dir = System.Web.HttpContext.Current.Server.MapPath(filePath);
                            if (!Directory.Exists(dir))
                                Directory.CreateDirectory(dir);
                            string oldName = file.FileName;
                            string ext = oldName.Substring(oldName.LastIndexOf("."));
                            string newName = DateTime.Now.ToString("ddHHmmssfff") + ext;
                            string url = filePath + newName;
                            file.SaveAs(dir + newName);
                            imgs += "网址" + url + ",";
                        }
                    }
    
                    //添加、更新到数据库
    
                }
                catch (Exception ex)
                {
                    Log.Error("=========上传图片错误:" + ex.Message + "=============");
                    return Json(new { Result = "fail", Response = ex.Message });
                }
                return Json(new { Result = "ok", Response = imgs.TrimEnd(',') });
            }
  • 相关阅读:
    test20180922 倾斜的线
    test20180921 量子纠缠
    test20180921 手机信号
    test20180919 选择客栈
    BZOJ3083 遥远的国度
    test20180907 day1
    [ZJOI2010]基站选址
    HDU3584 Cube
    POJ2155 Matrix
    test20180902 day1
  • 原文地址:https://www.cnblogs.com/dances/p/7560651.html
Copyright © 2011-2022 走看看