簡體   English   中英

在 .net 5 的 Blazor 客戶端 WebAssembly 上使用 InputFile

[英]Using InputFile on Blazor client WebAssembly with .net 5

我正在做這個教程來創建一個機器學習應用程序( https://www.dotnetcurry.com/aspnet-core/1537/blazor-ml-dotnet )。 我想將我的應用程序從 Blazor 服務器轉換為 Blazor 客戶端。

但我對 .net 5 上的 InputFile 有疑問。

@page "/identify"
@using System.Collections.Generic
@using BlazorClient.Data
@using BlazorInputFile
 
<div class="container">
  <h1>Identify image</h1>
 
  <p>
    This component allows sending an image to run the image recognition model.
    Select an image to start the upload and recognition process.
  </p>
  <form>
    <InputFile multiple OnChange="OnImageFileSelected" accept="image/*"/>
  </form>
 
  <div class="row my-4">
    @foreach (var image in selectedImages)
    {
      <div class="col-4">
        <p>@image.Name</p>
      </div>
    }
  </div>
</div>
 
 
@code {
    List<IFileListEntry> selectedImages = new List<IFileListEntry>();
 
    void OnImageFileSelected(IFileListEntry[] files)
    {
        selectedImages.AddRange(files);
    }
}

我的錯誤列表

我用這個解決方案解決了我的問題:

    IReadOnlyList<IBrowserFile> selectedImages;

    void OnImageFileSelected(InputFileChangeEventArgs eventArgs)
    {
        const int MaxAllowedFiles = 5;
        selectedImages = eventArgs.GetMultipleFiles(MaxAllowedFiles);
    }

暫無
暫無

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

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