1

I have a method to return file from web api

 public static HttpResponseMessage FileAsFileAttachment(byte[] bytes, string filename)
    {
        var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(bytes) };

        result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

        result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = filename};

        return result;
    }

How can i read Content-Disposition header from responce?

 this.httpClient.fetch(`/company/get-asic-fee-autocomplete`).then(data=> { console.log(data.headers.get("Content-Disposition "))});

this header always null

How get filename and show all headers in aurelia fetch-client???

2 Answers2

0

Just summing this up whoever next encounters the issue.
As mentioned above if you have CORS enabled, then

By default, only the 7 CORS-safelisted response headers are exposed, even though I could see content in response header when debugging. Take a look at https://developer.mozilla.org/de/docs/Web/HTTP/Headers/Access-Control-Expose-Headers

The Solution: add this code on the server side

Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
ecif
  • 311
  • 2
  • 12
-1

A CORS-safelisted response-header name, given a CORS-exposed header-name list list, is a header name that is one of

Cache-Control Content-Language Content-Type Expires Last-Modified Pragma

any other headers are forbidden in aurelia fetch-client

Any value in list that is not a forbidden response-header name.

more info in documentation here