How to download a file in ASP.NET Core?

Your controller should return an IActionResult, and use the File method, such as this:

[HttpGet("download")]
public IActionResult GetBlobDownload([FromQuery] string link)
{
    var net = new System.Net.WebClient();
    var data = net.DownloadData(link);
    var content = new System.IO.MemoryStream(data);
    var contentType = "APPLICATION/octet-stream";
    var fileName = "something.bin";
    return File(content, contentType, fileName);
}

Leave a Comment