这是我的任务
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或讨论此部分,但没有成功,该任务只接受png、jpg等文件。我如何接受其他类型的文件,如pdf,txt?
看看这里:https://learn.microsoft.com/en-us/aspnet/core/blazor/file-uploads?view=aspnetcore-6.0&pivots=服务器
private int maxAllowedFiles = 3;
private async Task LoadFiles(InputFileChangeEventArgs e)
{
foreach (var file in e.GetMultipleFiles(maxAllowedFiles))
{
DO YOUR STUFF
}
}
Blazor不会限制您上传的文件类型。这必须由你自己完成。为了告诉<InputFile />
组件应该上传哪些文件,您需要自己指定。
例如:
<InputFile OnChange="OnInputFileChange" class="form-control" accept="application/pdf" />