首页 > 编程语言 >C# - 文件下载API接口实现

C# - 文件下载API接口实现

时间:2023-03-20 10:25:33浏览次数:39  
标签:文件 C# httpResponseMessage 接口 Content API new id 下载

/// <summary>
/// 下载文件
/// </summary>
/// <param name="id">文件ID</param>
/// <returns>返回文件下载链接</returns>
[HttpGet]
[Route("api/Production/FileDownLoad")]
public IHttpActionResult FileDownLoad(string id)
{
var PhysicalPath= GetPhysicalPath(id);
HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK);
FileStream fileStream = File.OpenRead(PhysicalPath);  //文件物理路径
httpResponseMessage.Content = new StreamContent(fileStream);
httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = HttpUtility.UrlEncode(Path.GetFileName(OriginalName))  //设置文件名称
};

return ResponseMessage(httpResponseMessage);
}

 

标签:文件,C#,httpResponseMessage,接口,Content,API,new,id,下载
From: https://www.cnblogs.com/jxw-29/p/17235357.html

相关文章

  • wpa_supplicant中产生__cfi_check错误crash解法
    wifi的crash问题在于以下指定几个wpa会用到的so。wpa该平台是原生的,以下几个s0用原生的就行了。用mtk的hal层的s0会出错我想是因为wpa在mtk的平台不是存原生,加了很多接口以......
  • cssnote
    bfc(BlockFormattingContext)实现bfc方法1.body根元素2.设置浮动,不包括none3.设置定位,absoulte或者fixed4.行内块显示模式,inline-block5.设置overflow,即hidden,auto,s......
  • https://www.cursor.so/
    Cursor|BuildFast GPT-4自动写代码刚刚发布的Cursor编辑器集成了GPT-4接口,我测试了下他生成代码的能力,叹为观止,我尝试了从前端到后段,从纯软到软硬结合,从UE到U......
  • CentOS7官网详细下载教程
    进入CentOS官网下载,我是Windows操作系统,选择的是x86_64(点击x86_64)这里随便选择一个下载源,我选的是:http://mirrors.nju.edu.cn/centos/7.9.2009/isos/x86_64/进入下载源......
  • 密码学SAT入门文献1——Algebraic and Logic Solving Methods for Cryptanalysis
    密码学SAT入门文献2——CDCL(Crypto)SATSolversforCryptanalysis  Abstract Algebraicsolvingofpolynomialsystemsandsatisfiabilityofproposi......
  • EmployeeController类的分页查询page方法
    @GetMapping("/page")publicR<Page>page(intpage,intpageSize,Stringname){log.info("page={},pageSize={},name={}",page,pageSize,name);//构造分页......
  • EmployeeController类的根据id修改员工信息update方法
    @PutMappingpublicR<String>update(HttpServletRequestrequest,@RequestBodyEmployeeemployee){log.info(employee.toString());//获取当前登录用户id/......
  • EmployeeController类的根据id查询员工信息getById方法
    @GetMapping("/{id}")publicR<Employee>getById(@PathVariableLongid){log.info("根据id查询员工信息。。。");Employeeemployee=employeeService.getById......
  • apple M1 python开发,django,安装mysqlclient并使用
    前言此笔记记录了MBPM1芯片的苹果本,解决mysqlclient虽然安装成功,但是会遇到_namenotdefound的解决办法解决过程内容参考:https://github.com/PyMySQL/mysqlclient/iss......
  • Android AsyncTask异步任务的使用
    文章目录​​小结​​​​定义异步任务类​​​​开启异步任务​​​​参考​​小结可以使用androidAsyncTask来执行繁重的后台任务,以避免UI界面无响应,并可以实时在UI界面......