what would be the best approach when downloading file from a database (uploaded with fileInput)? My idea is to put a button that would initialize the download, but I'm not sure what would be the best approach either to download a file or pass it to browser to display it (pdf). Can this be done through invoking a custom method? I'd like to use radzen ide and blazor components as much as possible. Some examples on the net are involving some JSinterop but I would rather avoid it. I'm sure someone already has done it, I would really appreciate directions.
Thnx. I have gone through all relevant posts. I have implemented a custom class that returns FileStreamResult. I have binded the call (getfile(id)) on the click event of the button, but this does not start the download on client side, though I can see that the event is fired and data is returned. I must be missing something?
Maybe for all those looking for a solution.
If you used a FileInput file and looking for the other half of the code to download or show document here is one of the shortest paths.
The simplest way is to create another controller
public IActionResult GetDocument(int id)
var queryresult = Context.Documents.Where(doc => doc.id == id).FirstOrDefault();
//var queryresult = Context.Documents.Where(query).FirstOrDefault();
if (queryresult == null || queryresult.document1 == null)
var storedstring = queryresult.document1; //the Base URI encoded string (if uploaded through fileInput --> starts with "data: mime ;base64,")
var filename = queryresult.filename;
if (!filename.EndsWith(".pdf")) filename += ".pdf";
var mime = storedstring.Substring(storedstring.IndexOf(':') + 1, storedstring.IndexOf(';') - storedstring.IndexOf(':') - 1);
storedstring = storedstring.Replace("data:" + mime + ";base64,", "");
byte byteArr = Convert.FromBase64String(storedstring);
System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
FileName = filename,
Inline = false // false = prompt the user for downloading; true = browser to try to show the file inline
return File(byteArr, mime);
since the response has to come from the server with a specific headers so browser will recognize it. Than all that is left is to create a Button and bind its Click event to a c# code that navigates to download controller: