码迷,mamicode.com
首页 > Windows程序 > 详细

Asp.Net Web Api 图片上传

时间:2015-02-09 12:32:57      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:

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 图片上传

标签:

原文地址:http://www.cnblogs.com/fx2008/p/4281011.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!