Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get content-disposition from http.get header?

I am trying to download a file using web API + Angularjs and it's working fine, however I'm sending 'content-disposition' in the header from the web API but I'm unable to access it in the response-header.

WebAPI:

[HttpGet]
[AllowCrossSiteJson]
public HttpResponseMessage GetAcquisitionsTemplate()
{
    var docContent = _d.FirstOrDefault();
    Stream stream = new MemoryStream(docContent.Content);
    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
    string contentDisposition = string.Concat("attachment; filename=", docContent.Name.Replace(" ", String.Empty), "." + docContent.Extension);
    result.Content = new StreamContent(stream);
    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");    
    result.Content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse(contentDisposition);
    return result;            
}

Client Side (AngularJs):

$http.get(url)success(function (data, status, headers) {
    var header= headers();
})

In the header I'm getting the following values but I'm unable to get content-disposition. Please correct me where I'm wrong?

enter image description here

like image 633
Manjit Singh Avatar asked Mar 23 '16 10:03

Manjit Singh


1 Answers

I guess you are trying to hit it from localhost while the file is hosted on the server, in that case ask your server team to allow , Access-Control-Expose-Headers(‘Content-Disposition’) . With this Header, custom headers like COntent-Disposition will be accessible to you over cross domain

like image 85
Achyut Avatar answered Sep 18 '22 15:09

Achyut