Content negotiation for File Download In Web API

Kokirala Sudheer

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?

Darrel Miller

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Web API download locks file

From Dev

Simulate file download with WEB API

From Dev

Web API load Content file

From Dev

How to download a web page content to a text file exactly as the web page is?

From Dev

Angular download csv file with Web Api 2

From Dev

web api download xml file from javascript

From Dev

Web api large file download with HttpClient

From Dev

Why Web Api HttpResponseMessage not download the file?

From Dev

Web api large file download with HttpClient

From Dev

Why Web Api HttpResponseMessage not download the file?

From Dev

download a file with play web api (async)

From Dev

Is there better approach to Accept Header based content negotiation in Spring API?

From Dev

Why would HTTP content negotiation be preferred to explicit parameters in an API scenario?

From Dev

Download partial content for a file attachment of a message using MicrosoftGraph API

From Dev

Content negotiation to return HTML

From Dev

PhalconPHP: content negotiation?

From Dev

Restlet Content Type Negotiation

From Dev

Content negotiation using WebSharper

From Dev

PhalconPHP: content negotiation?

From Dev

download csv file from web api in angular js

From Dev

Web API 2 download file using async Task<IHttpActionResult>

From Dev

Web API WorkBook download

From Dev

Download html textarea content as a file

From Dev

Download file with specific content type

From Dev

Mandrill API - download email content

From Dev

Spring boot controller content negotiation

From Dev

Jersey - content negotiation for error handling

From Dev

API File Download

From Java

Dynamically-created content for download without writing a file on server-side in Vaadin Flow web app

Related Related

HotTag

Archive