Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (5.8k points)

I have an MVC project that will display some documents to users. The files are currently stored in Azure blob storage.

Currently, the documents are retrieved from the following controller action:

[GET("{zipCode}/{loanNumber}/{classification}/{fileName}")]

public ActionResult GetDocument(string zipCode, string loanNumber, string classification, string fileName)

{

    // get byte array from blob storage

    byte[] doc = _docService.GetDocument(zipCode, loanNumber, classification, fileName);

    string mimeType = "application/octet-stream";

    return File(doc, mimeType, fileName);

}

Right now, when a user clicks on a link like the following:

<a target="_blank" href="http://...controller//GetDocument?zipCode=84016&loanNumber=12345678classification=document&fileName=importantfile.pdf

Then, the file downloads to their browser's downloads folder. What I would like to happen (and I thought was default behavior) is for the file to simply be displayed in the browser.

I have tried changing the mime type and changing the return type to FileResult instead of ActionResult, both to no avail.

How can I make the file display in the browser instead of downloading it?

1 Answer

0 votes
by (9.6k points)

Here is the correct code:

public FileContentResult GetDocument(string zipCode, string loanNumber, string classification, string fileName)

{

    byte[] doc = _docService.GetDocument(zipCode, loanNumber, classification, fileName);

    string mimeType = "application/pdf"

    Response.AppendHeader("Content-Disposition", "inline; filename=" + fileName);

    return File(doc, mimeType);

Related questions

+4 votes
2 answers
0 votes
1 answer
0 votes
1 answer

Browse Categories

...