I am using BlazorInputFile and I am having trouble figuring out how to filter my file type to just accept txt files
async Task HandleSelection(BlazorInputFile.IFileListEntry[] files)
{
try
{
var file = files.FirstOrDefault();
if (file != null)
{
if (file.Type != "application/text")
{
PopupModel = new PopupModel
{
Message = "Please select .txt file.",
MessageType = MessageType.Info,
Show = true
};
return;
}
You can filter it client side like you would with an HTML file input.
Caution: your idea of what's an acceptable file and Chrome or Firefox's is not guaranteed to be the same. Depending on what you're doing with the file, you might want to check it programmatically-- for example, if your text file contains query strings or html markup or something.