Kokirala Sudheer
Kokirala Sudheer

Reputation: 439

Content negotiation for File Download In Web API

I have a Web API REST service method, which returns the pdf file. And the code is as follows:

 string content = some byte array;

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            result.Content = new StringContent(content);
            //a text file is actually an octet-stream (pdf, etc)
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
            //we used attachment to force download
            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
            result.Content.Headers.ContentDisposition.FileName = "mypdf.pdf";
            return result;

My doubt is for the other methods in the API, I used content negotiation for the media type of the response. Do I need to use the content negotiation here also?? Is it need here or not?

Upvotes: 1

Views: 1030

Answers (1)

Darrel Miller
Darrel Miller

Reputation: 142222

No. Conneg is a purely optional thing. If your resource only has a application/pdf representation then so be it.

Upvotes: 2

Related Questions