zoukankan      html  css  js  c++  java
  • web api 上传

    using System.Net;
    using System.Net.Http;
    using System.Web;
    using System.Web.Http;
     
    namespace FileUploadTest.Controllers
    {
    public class FileUploadController : ApiController
    {
        public async Task<HttpResponseMessage> Post()
        {
            if (Request.Content.IsMimeMultipartContent())
            {
                var path = HttpContext.Current.Server.MapPath("~/App_Data");
                var provider = new MultipartFormDataStreamProvider(path);
                await Request.Content.ReadAsMultipartAsync(provider).ContinueWith(t =>
                {
                    if (t.IsFaulted || t.IsCanceled)
                        throw new HttpResponseException(HttpStatusCode.InternalServerError);
                });
                //Here you should return a meaningful response
                return Request.CreateResponse(HttpStatusCode.OK); 
            }
            else
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"));
            }
        }
    }
    }
  • 相关阅读:
    内存分布
    多态的作用
    c++虚函数实现与this指针
    Makefile 初探
    编译性语言和解释性语言
    从今天开始学好C++
    Java基础
    程序流程控制
    Java运算符
    初识Java
  • 原文地址:https://www.cnblogs.com/fx2008/p/3301427.html
Copyright © 2011-2022 走看看