model-view-controller - 无法下载 PDF 文件,从 Sql 数据库中获取。已获取字节值,函数未出现任何错误,但未下载 PDF
问题描述
我无法下载从 Sql 数据库获取的 PDF 文件。字节值已被提取,函数没有抛出任何错误,但没有下载 PDF。
代码:
public ActionResult PrintPDF(string projectSelection)
{
byte[] extract = (byte[])_selectionManager.FindPdf();
MemoryStream pdfStream = new MemoryStream();
pdfStream.Write(extract, 0, extract.Length);
pdfStream.Position = 0;
HttpContext.Response.AddHeader("content-disposition",
"attachment; filename=form.pdf");
return new FileStreamResult(pdfStream, "application/pdf");
}
解决方案
既然您已经将文件内容作为字节,为什么将其转换为流?
请检查这是否有效
byte[] extract = (byte[])_selectionManager.FindPdf();
return File(
extract, System.Net.Mime.MediaTypeNames.Application.Pdf, "form.pdf");
推荐阅读
- reactjs - 获取 url.split 不是 getFilenameFromURLin Filepond 和 React-Filepond 的功能
- angular - Angular 5 AOT 编译失败
- javascript - 为什么使用 FileReader 读取文件内容时 setState 不起作用?
- amazon-cloudformation - AWS Cloudformation 对 EKS Fargate 的支持
- c - 从'struct net *'分配给'u32'(又名'unsigned int')的整数转换指针不兼容
- c++ - 为右值参数隐式生成函数重载?
- html - CSS 不居中
- .net-core - 第十条记录的主键冲突
- java - 下面的“if 语句”如何真正与多个“OR”运算符一起使用
- javascript - CSS:透明图像叠加输入字段