簡體   English   中英

將文件上傳器綁定到 Blazor 中的模型

[英]Binding file uploader to a model in Blazor

Blazor 中的綁定文件上傳器無法與 razor 組件中的 @bind 屬性一起使用

當表單使用兩種方式綁定參數提交時,我已經構建了模型,它適用於除文件上傳器之外的標准組件,

我不知道綁定文件上傳器的參數類型是什么

這是我的提交功能

 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;
            }
        }

當我嘗試時,nikImage 為空我希望我可以在將文件發布到我的 Web API 之前對其進行操作

您的代碼含糊不清,無法真正解密。 但是,我認為您不能在客戶端Blazor上使用IFromFile。 您可以在服務器端Blazor中使用IFormFile。

如果要從<input type=file>獲取該數據,則必須通過諸如使用JS interop 通過input type = file獲取字節數組之類的方法來獲取二進制數據。

樣品

https://github.com/aspnet/AspNetCore/issues/10552 https://remibou.github.io/Upload-file-with-Blazor/

希望這可以幫助...

thx的信息

我已經找到了該鏈接,並且似乎做錯了所有東西,因為我找不到有關上傳的任何最新工作示例,因此我使用的是syncfusion uploader文件,但由於默認的signalR消息大小為32KB,因此需要進行一些調整,因此它可以上傳較大的文件(需要3天的時間才能上傳)

services.AddSignalR(e =>
{
    e.MaximumReceiveMessageSize = 5000000;
});

這些https://github.com/aspnet/AspNetCore/issues/11643的答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM