MojoFilter
MojoFilter

Reputation: 12286

Generated image display vs. download

I have an MVC action that pulls an image from a database and sends it in the response via the File(byte[], string) method. When I navigate to the action in my browser, it downloads the file rather than display it in the browser.

I'm setting the file and setting the content type to "image/jpeg". Is there another header that needs to be set in order to get it to do what I want it to do?

Upvotes: 2

Views: 258

Answers (3)

MojoFilter
MojoFilter

Reputation: 12286

Ok, mystery solved.

Controller.File() has an overload that takes no filename; just data and content-type. Using that overload causes the content-disposition to be set correctly. In retrospect, I guess that makes a lot of sense.

Upvotes: 2

David
David

Reputation: 34573

I would use Fiddler to compare your response headers with a normal static JPG's response headers. That will tell you for sure.

Upvotes: 0

Jonathan Rupp
Jonathan Rupp

Reputation: 15772

Response.ContentType

Response.ContentType = "image/jpeg";

Upvotes: 1

Related Questions