这是我的任务
private async Task UploadFiles(InputFileChangeEventArgs inputFileChangeEventArgs)
{
_CarregaFoto = true;
var fileFormat = "image/png";
var MAXALLOWEDSIZE = 60000000;
var imageFile = await inputFileChangeEventArgs.File.RequestImageFileAsync(fileFormat, 6000, 6000);
var buffer = new byte[imageFile.Size];
await imageFile.OpenReadStream(MAXALLOWEDSIZE).ReadAsync(buffer);
AnexoDenunciaModel _novaFoto = new AnexoDenunciaModel();
_novaFoto.imagem = buffer;
_novaFoto.id_ocorre = id;
_novaFoto.nome = imageFile.Name;
_novaFoto.Denunciante = true;
await _db.InsertAnexoDenuncia(_novaFoto);
_CarregaFoto = false;
await LeTabelas2();
}
我试过将var fileFormat更改为pdf或discart这部分,但没有成功,该任务只接受png,jpg等文件。我怎么能接受其他类型如pdf,txt文件?
2条答案
按热度按时间flvlnr441#
请看这里:https://learn.microsoft.com/en-us/aspnet/core/blazor/file-uploads?view=aspnetcore-6.0&pivots=server
sc4hvdpw2#
Blazor并没有限制你上传的文件类型。这需要你自己来完成。为了告诉
<InputFile />
组件应该上传哪些文件,你需要自己指定。例如: