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.";
            }
        }

上一篇:FIS3使用官方例子流程


下一篇:web前端图片上传