Case Clicker 2
Loading...
Loading Website...
[HttpGet] public IActionResult DownloadFile() { // 1. Get your byte array (e.g., from a database or service) byte[] fileBytes = GetFileByteArray(); // 2. Define the content type (e.g., "application/pdf" or "image/png") string contentType = "application/octet-stream"; // Generic binary data // 3. Define the file name that will appear in the user's browser string fileName = "Report.pdf"; // Returns a FileContentResult which triggers the browser download return File(fileBytes, contentType, fileName); } Use code with caution. 2. Common MIME Types
To trigger a download, your controller action should return a FileResult . The File() method takes the byte array, the MIME type , and an optional file name. .net core download file from byte array
Downloading files from a byte array in .NET Core is a common requirement for applications that generate documents on the fly (like PDFs or Excel reports) or retrieve binary data from a database. [HttpGet] public IActionResult DownloadFile() { // 1
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet Images: image/png or image/jpeg Generic/Unknown: application/octet-stream 3. Key FileResult Variations Define the file name that will appear in