You can try to read the file from your storage as a byte array and use the File method to return it from the action method.
public ActionResult View(int id) {
Assuming GetFileInByteArrayFormatFromId returns the byte version of the file after reading from your repository / azure. You might want to consider caching certain files in your environment so that you donβt have to turn to azure writing to get it for every request.
If you can read the file as a file stream, the File method has an overload, which also takes this value
public ActionResult View(int id) {
And if you have a file available on your server (cached files), you can use another overload of the File method, where you will pass the path instead of an array of bytes.
public ActionResult View(int id) { var f = Server.MapPath("~/Content/Downloads/sampleFile.pdf"); return File(f,"application/pdf"); }
If the browser has support for displaying the type of response content, the response will be displayed in the browser. Most major browsers support PDF rendering.
There is another overload of the File method, which uses the name of the download file, which will use the browser save / load dialog so that the user can save his local computer and / or open it.
public ActionResult View(int id) { var pathToTheFile=Server.MapPath("~/Content/Downloads/sampleFile.pdf"); return File(pathToTheFile, MimeMapping.GetMimeMapping(pathToTheFile),"Myfile.pdf"); } public ActionResult ViewFromByteArray(int id) { byte[] byteArrayOfFile=GetFileInByteArrayFormatFromId(id); return File(byteArrayOfFile, "application/pdf","Myfile.pdf"); }
In this case, the user will receive an invitation to download from the browser.