Created
September 16, 2020 09:37
-
-
Save csharpforevermore/50196adca280283e782b43b86502ab81 to your computer and use it in GitHub Desktop.
Return a PDF as a file from a web API service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet] | |
public FileStreamResult Download() | |
{ | |
var stream = System.IO.File.OpenRead(AppSettings.PdfFileName); | |
return new FileStreamResult(stream, AppSettings.MimeType); | |
} | |
[HttpGet("open-pdf")] | |
public IActionResult Get() | |
{ | |
FileStream stream = GetFileBytesById(AppSettings.PdfFileName); | |
if (stream == null) | |
return NotFound(); | |
return File(stream, AppSettings.MimeType); | |
} | |
[HttpGet("download/{name}")] | |
public FileStreamResult DownloadByNamec(string name) | |
{ | |
var stream = GetFileBytesById(AppSettings.PdfFileName); | |
return new FileStreamResult(stream, AppSettings.MimeType) | |
{ | |
FileDownloadName = AppSettings.PdfFileName | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment