相关疑难解决方法(0)

ASP.Net核心内容 - 处置附件/内联

我从WebAPI控制器返回一个文件.Content-Disposition标头值自动设置为"attachment".例如:

性格:依恋; 文件名= "30956.pdf"; 文件名*= UTF-8''30956.pdf

当它设置为附件时,浏览器将要求保存文件而不是打开它.我想打开它.

如何将其设置为"内联"而不是"附件"?

我正在使用此方法发送文件:

public IActionResult GetDocument(int id)
{
    var filename = $"folder/{id}.pdf";
    var fileContentResult = new FileContentResult(File.ReadAllBytes(filename), "application/pdf")
    {
        FileDownloadName = $"{id}.pdf"
    };
    // I need to delete file after me
    System.IO.File.Delete(filename);

    return fileContentResult;
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

31
推荐指数
6
解决办法
3万
查看次数

使用Angular的新HttpClient,如何在订阅事件时获取所有标头?

我使用Angular 4.3.2和新的HttpClient来下载作为流发送的文件,我需要获取标题(特别是Content-Disposition),但它们似乎没有出现在响应中,即使我可以在Chrome的开发工具中查看使用该请求正确发送的标头.

这是代码:

downloadDocument(documentId: number) {
    const downloadDocumentUrl = `${ this.config.apiUrls.documents }/${ documentId }`;
    const downloadRequest = new HttpRequest('GET', downloadDocumentUrl, {
        reportProgress: true,
        responseType: 'blob'
    });

    let percentageDownloaded = 0;
    this.http.request(downloadRequest).subscribe(
        (event: HttpEvent < any > ) => {
            if (event) {
                switch (event.type) {
                    case HttpEventType.ResponseHeader:
                        const contentDispositionHeader = event.headers.get('Content-Disposition');
                        console.log(contentDispositionHeader); // Always null here although I expected it to be there.
                        break;

                    case HttpEventType.DownloadProgress:
                        if (event.total) {
                            percentageDownloaded = Math.round((event.loaded / event.total) * 100);
                        }
                        break; …
Run Code Online (Sandbox Code Playgroud)

angular

7
推荐指数
1
解决办法
8804
查看次数

标签 统计

angular ×1

asp.net-core ×1

c# ×1