Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-Disposition header is not available #37836

Closed
zendu opened this issue Jun 30, 2020 · 2 comments
Closed

Content-Disposition header is not available #37836

zendu opened this issue Jun 30, 2020 · 2 comments

Comments

@zendu
Copy link

zendu commented Jun 30, 2020

馃悶 bug report

Affected Package

The issue is caused by package @angular/common/http

Is this a regression?

Not sure

Description

Content-Disposition header is not returned by response.headers even when server sends it.

馃敩 Minimal Reproduction

 return this.http.get(this.formatUrl(url), {
  headers: httpOptions.headers,
  params: httpOptions.params,
  responseType: 'blob',
  observe: 'response'
}).pipe(
  map((response: HttpResponse<Blob>) => {
    // header looks like --> Content-Disposition: attachment; filename="filename.extn"
    if (response.headers.has(ContentDispositionHeaderName)) {
      // select value filename="filename.extn" --- *THIS CODE IS NEVER HIT*
      const fileNameValue = response.headers.getAll(ContentDispositionHeaderName).filter(x => x.startsWith('filename='))[0];
      if (fileNameValue) {
        // extract value --> filename.extn
        const fileName = fileNameValue.split('=').map(x => x.replace('"', ''))[1];
        if (fileName) {
          return new File([response.body], fileName);
        }
      }
    }

    return response.body;
  })
);

馃敟 Exception or Error





馃實 Your Environment

Angular Version:




Angular CLI: 9.1.4
Node: 12.18.1
OS: win32 x64

Angular: 9.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.901.4
@angular-devkit/build-angular      0.901.4
@angular-devkit/build-ng-packagr   0.901.4
@angular-devkit/build-optimizer    0.901.4
@angular-devkit/build-webpack      0.901.4
@angular-devkit/core               9.1.4
@angular-devkit/schematics         9.1.4
@ngtools/webpack                   9.1.4
@schematics/angular                9.1.4
@schematics/update                 0.901.4
ng-packagr                         9.1.2
rxjs                               6.5.5
typescript                         3.8.3
webpack                            4.42.0

Anything else relevant?

@pkozlowski-opensource
Copy link
Member

This has nothing to do with Angular but rather with how browsers expose headers. See https://stackoverflow.com/questions/45892875/unable-to-view-content-disposition-headers-in-angular4-get-response and many other similar questions

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants