Skip to content

Blazor InputImage Component #38679

Closed
Closed
@pawelel

Description

@pawelel

Is your feature request related to a problem? Please describe.

Need to upload file and resize it if it is too large.
Using RequestImageFileAsync omit files with dimensions less than given parameters.
The issue is that height and width of an image are inaccessible directly from blazor.

Describe the solution you'd like

InputImage could inherit from InputFile

<InputImage id="fileInput" OnChange="UploadFile" hidden />
string PhotoPath ="";
async Task UploadFile(InputFileChangeEventArgs e)
    {
        var file = e.File;

var resizedImage= await file.RequestImageFileAsync(imageType, 200, 200);
if(resizedImage.Height>file.Height || resizedImage.Width>file.Width)
{
var buffer = new byte[file.Size];
                await resizedImage.OpenReadStream().ReadAsync(buffer);
                PhotoPath = $"data:{imageType};base64,{Convert.ToBase64String(buffer)}";
                StateHasChanged();
}else
{
var buffer = new byte[resizedImage.Size];
                await resizedImage.OpenReadStream().ReadAsync(buffer);
                PhotoPath = $"data:{imageType};base64,{Convert.ToBase64String(buffer)}";
                StateHasChanged();
}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions