[英]Binding file uploader to a model in Blazor
Binding file uploader in Blazor not working with @bind attribute in razor component Blazor 中的绑定文件上传器无法与 razor 组件中的 @bind 属性一起使用
i've build the model when the form is Submit using two way binding parameter and it works for standard componenent except file uploader,当表单使用两种方式绑定参数提交时,我已经构建了模型,它适用于除文件上传器之外的标准组件,
i don't know what is the paramter type for binding file uploader我不知道绑定文件上传器的参数类型是什么
here is my Submit function这是我的提交功能
protected async Task OnSubmit()
{
...
error = null;
try
{
...
//nikImagewas my intention to 'hold' the file image. its type is IFormFile
customer.NIKImage = nikImage;
var response = await _state.PostAsync(WebsVariables.Urls.CreateCustomerDraftObject, customer);
if (response.IsSuccessStatusCode)
{
...
}
else
{
var msg = await response.Content.ReadAsStringAsync();
_toastService.ShowError(msg);
}
//clear();
this.StateHasChanged();
}
catch (Exception ex)
{
error = ex.Message;
}
}
when i try it, the nikImage is null i expected i can manipulate the file before POST it to my web API当我尝试时,nikImage 为空我希望我可以在将文件发布到我的 Web API 之前对其进行操作
Your code is vague and cannot really be deciphered. 您的代码含糊不清,无法真正解密。 However, I think that you cannot use IFromFile on client-side Blazor.
但是,我认为您不能在客户端Blazor上使用IFromFile。 You may use IFormFile in server-side Blazor.
您可以在服务器端Blazor中使用IFormFile。
If you want to get that data from an
<input type=file>
, you'd have to get the binary data via something like Getting byte array through input type = file using JS interop如果要从
<input type=file>
获取该数据,则必须通过诸如使用JS interop 通过input type = file获取字节数组之类的方法来获取二进制数据。
https://github.com/aspnet/AspNetCore/issues/10552 https://remibou.github.io/Upload-file-with-Blazor/ https://github.com/aspnet/AspNetCore/issues/10552 https://remibou.github.io/Upload-file-with-Blazor/
Hope this helps... 希望这可以帮助...
thx for the info thx的信息
i already find that link and it seems i do it all wrong since i can't find any newest working sample about Uploading hence i'm using syncfusion uploader file but it needs to be tweaked a bit since the default signalR message size is 32KB, so it can upload larger file (3 days looking for these) 我已经找到了该链接,并且似乎做错了所有东西,因为我找不到有关上传的任何最新工作示例,因此我使用的是syncfusion uploader文件,但由于默认的signalR消息大小为32KB,因此需要进行一些调整,因此它可以上传较大的文件(需要3天的时间才能上传)
services.AddSignalR(e =>
{
e.MaximumReceiveMessageSize = 5000000;
});
the answer from these https://github.com/aspnet/AspNetCore/issues/11643 这些https://github.com/aspnet/AspNetCore/issues/11643的答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.