issue with the input tag

Saeed Pooladzadeh 221 Reputation points
2023-11-12T22:10:25.4233333+00:00

Hello,

I need to import an image in my Blazor web assembly app. I have tested and read a lot of content from the web and AI.
But I don't know why none of my input tags are working!

<InputFile @OnChange="HandleFileUpload" />
<input type="file" @onchange="HandleFileUpload" />
<input type="file" @onchange="HandleFileUpload" />
private async Task HandleFileUpload(InputFileChangeEventArgs e)
    {
        var file = e.File;
        var buffer = new byte[file.Size];
        await file.OpenReadStream().ReadAsync(buffer);

        // Send the image to DeepAI for processing
        var generatedAvatar = await GenerateAvatar(buffer);

        // Display the generated avatar
        avatarUrl = $"data:image/png;base64,{Convert.ToBase64String(generatedAvatar)}";
        isImageUploaded = true;
        isAvatarGenerated = true;
    }

Please guide me.

thanks,

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
3,754 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,191 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Ping Ni-MSFT 490 Reputation points Microsoft Vendor
    2023-11-16T06:01:00.5766667+00:00

    Hi @Saeed Pooladzadeh,

    You could F12 in the browser and check the Console panel to see the exception:

    No parameterless constructor defined for type 'namespace.Index'
    

    So just add the constructor:

    @code {
        //....
        public Index()
        {
        }
        public Index(HttpClient httpClient) {
           this.httpClient = httpClient; 
        }
        //.....
    }
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Rena


  2. Saeed Pooladzadeh 221 Reputation points
    2023-11-20T14:38:34.03+00:00

    But why does it need a parameterless constructor?

    0 comments No comments