本文转载自:http://www.cnblogs.com/zj1111184556/p/3494502.html

public class FileUploadController : ApiController
{ public async Task<HttpResponseMessage> Post()
{
// 检查是否是 multipart/form-data
if (!Request.Content.IsMimeMultipartContent("form-data"))
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
HttpResponseMessage response = null; try
{
// 设置上传目录
var provider = new MultipartFormDataStreamProvider(@"F:\\StudyProject\\webapi2demo\\CSdemo\\UpLoad");
// 接收数据,并保存文件
var bodyparts = await Request.Content.ReadAsMultipartAsync(provider);
response = Request.CreateResponse(HttpStatusCode.Accepted);
}
catch
{
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
return response;
}
}
public class FileUploadController : ApiController
{
public string Post()
{ HttpPostedFile file = HttpContext.Current.Request.Files[];
string strPath = "D:\\MyProjects\\StudySolution\\RestDemo\\Upload\\test2.rar" ;
file.SaveAs(strPath);
string result = ""; return result;
}
}

(转)WebApi 上传文件的更多相关文章

  1. Owin WebAPI上传文件

    Owin是微软出了几年的东东了,一直没时间学习.大概了解了下,是一个脱离IIS环境,快速搭建WebAPI服务的东西. 刚好想尝试下尽量脱离IIS创建简单快捷配置的项目,就是用了Nginx+Owin的模 ...

  2. Asp.Net Core WebApi 和Asp.Net WebApi上传文件

    public class UpLoadController : ControllerBase { private readonly IHostingEnvironment _hostingEnviro ...

  3. webAPI 上传文件 404错误(转载)

    webAPI文件上传时文件过大404错误的问题  来源:https://www.cnblogs.com/dzhengyang/p/9149157.html 背景:最近公司有个需求,外网希望自动保存数据 ...

  4. WebApi上传文件

    上网搜了下Web Api上传文件的功能,发现都写的好麻烦,就自己写了一个,比较简单,直接上传文件就可以,可以用Postman测试. 简单的举例 /// <summary> /// 超级简单 ...

  5. .Net Core2.2 WebApi上传文件

    基于.net core2.2的webapi程序,接收客户端上传的文件.按照以下写法,file的值永远是null [HttpPost] public void Post([FromForm] IForm ...

  6. C# WebApi 上传文件

    本文转载自:http://www.cnblogs.com/zj1111184556/p/3494502.html public class FileUploadController : ApiCont ...

  7. 使用swagger上传文件

    经常使用swagger,可以通过设置[ProducesResponseType]标记接口的返回信息:swagger也能通过接口的参数列表,自动获得发送的数据结构信息. 不过有一个例外,就是上传文件的时 ...

  8. webApi上传下载文件

    上传文件通过webApi html端调用时包含(form提交包含 enctype="multipart/form-data",才可以启作用获取到文件) public class U ...

  9. WebAPI通过multipart/form-data方式同时上传文件以及数据(含HttpClient上传Demo)

    简单的Demo,用于了解WebAPI如何同时接收文件及数据,同时提供HttpClient模拟如何同时上传文件和数据的Demo,下面是HttpClient上传的Demo界面 1.HttpClient部分 ...

随机推荐

  1. 从 Spring Cloud 开始,聊聊微服务架构实践之路

    [编者的话]随着公司业务量的飞速发展,平台面临的挑战已经远远大于业务,需求量不断增加,技术人员数量增加,面临的复杂度也大大增加.在这个背景下,平台的技术架构也完成了从传统的单体应用到微服务化的演进. ...

  2. angularjs地址栏传参

    1:路由定义参数 2.controller 3. 4.目标得到参数值

  3. Linux 任务控制(bg job fg nohup &) (转)

    常用命令 & 将指令丢到后台中去执行[ctrl]+z 將前台任务丟到后台中暂停jobs 查看后台的工作状态fg %jobnumber 将后台的任务拿到前台来处理bg %jobnumber 将任 ...

  4. mooseFS学习篇

    官方网站:http://www.moosefs.org/ About MooseFS MooseFS is a fault tolerant, network distributed file sys ...

  5. 【scala】构造器

    和Java或C++一样,Scala可以有任意多的构造器. 不过Scala类有一个构造器比其他所有构造器都更为重要,它就是主构造器. 除了主构造器之外,类还可以有任意多的辅助构造器. 主构造器 在Sca ...

  6. 用工具快速建立hibernate框架

    ,一.建好项目后先导入两类jar包,一类是hibernate的jar包,一类是jdbc的jar包 二.点击“窗口”--“显示视图”--“其它”-“Hibernate configurations” 三 ...

  7. 使用PorterDuffXfermode画出刮刮奖效果p146-p148

    package com.zzw.Qunyinzghuan3; import android.content.Context; import android.graphics.Bitmap; impor ...

  8. LeetCode OJ:Lowest Common Ancestor of a Binary Tree(最近公共祖先)

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  9. UI-定时器与动画使用总结

    #pragma mark - 定时器   ******************************************************************************* ...

  10. 2017.10.26 ECN + product spec+ cypress ble module test+

    1 ECN Ecn  should be issued when modifying drawing,Copy children BOM of subassembly from BIL if one ...