gpt4 book ai didi

javascript - "Content-Disposition", "inline;filename="+ fileName 不强制显示 pdf 文件

转载 作者:行者123 更新时间:2023-12-02 22:14:21 25 4
gpt4 key购买 nike

我希望当首先单击链接时在新选项卡中显示 pdf 文件作为预览,然后允许用户下载该文件。

所以我寻找答案,他们大多说我应该包含这两个标题

Response.AddHeader("Content-Disposition", "inline; filename=\"" + filName + "\"");
Response.AddHeader("Content-Type", "application/pdf");

但它不起作用,pdf 文件才开始下载。这是我的代码:

C#:

public FileContentResult GetVisaAproveFile(Guid id)
{
var request = visaRequestRepository.GetById(id);
AttachedFile ApprovedAttachedFile = request.AttachedFiles.FirstOrDefault(f => f.DocType == DocType.ApprovedDocument);
byte[] filByte = ApprovedAttachedFile?.FileContent ?? new byte [0];
string filName = ApprovedAttachedFile?.AttachFileSource ?? "بدون عنوان";
Response.Clear();
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition", "inline; filename=\"" + filName + "\"");
return File(filByte, MimeMapping.GetMimeMapping(filName));
}

JavaScript:

$scope.onShowCertificate = function (e) {
debugger;
var id = e.key.VisaReqId;

var url = $window.location.origin + "/UploadFile/GetVisaAproveFile/?id=" + id;
$window.open(url, '_blank');

};

HTML:

<div data-options="dxTemplate:{ name:'Certificate' }">
<i class='glyphicon glyphicon-download-alt ajaxresub'
ng-if="item.value == 8"
style='color: blue;cursor: pointer !important;'
ng-click="onShowCertificate(item)"></i>
</div>

提前致谢:)

最佳答案

这是我的例子:

在您的操作中使用FileResult不要 reutrn File()。

返回FileStreamResult()

[HttpGet]
public FileResult GetVisaAproveFile(string id)
{
//skip content
//Put your PDF in MemoryStream
MemoryStream msResult = ReadPDF();

var fileResult = new FileStreamResult(msResult, "application/pdf");
Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}.pdf", id));

return fileResult;
}

关于javascript - "Content-Disposition", "inline;filename="+ fileName 不强制显示 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59443630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com