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"));
            }
        }
    }
    }
  • 相关阅读:
    nodejs install
    taobao sass
    Cors 跨域访问API
    多文件上传
    Next
    实用小工具
    下载包含src,tgz,zip的文件
    HTML5文件API
    Bootstrap (导航、标签、面包屑导航)
    Bootstrap 固定定位(Affix)
  • 原文地址:https://www.cnblogs.com/fx2008/p/3301427.html
Copyright © 2011-2022 走看看