Asp.Net Web Api 图片上传

public string UploadFile()
        {
            if (Request.Content.IsMimeMultipartContent())
            {
                //Save file
                MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath("/UploadUser/"));

                string filename = "Not set";

                IEnumerable<HttpContent> parts = null;
                Task.Factory
                    .StartNew(() =>
                    {
                        parts = Request.Content.ReadAsMultipartAsync(provider).Result.Contents;
                        filename = "Set Success";
                    },
                    CancellationToken.None,
                    TaskCreationOptions.LongRunning, // guarantees separate thread
                    TaskScheduler.Default)
                    .Wait();

                return filename;
            }
            else
            {
                return "Invalid.";
            }
        }
 

Asp.Net Web Api 图片上传

上一篇:将查询集SQL-存为物理 OR 临时表


下一篇:ASP.NET Identity(处理身份数据存储) 与 OWIN主机(实现katana验证授权)原理概括