Skip to content

Blazor InputImage Component #38679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pawelel opened this issue Nov 28, 2021 · 3 comments
Closed

Blazor InputImage Component #38679

pawelel opened this issue Nov 28, 2021 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-builtin-components Features related to the built in components we ship or could ship in the future ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved

Comments

@pawelel
Copy link

pawelel commented Nov 28, 2021

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();
}
}
@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Nov 29, 2021
@TanayParikh TanayParikh added the feature-blazor-builtin-components Features related to the built in components we ship or could ship in the future label Nov 29, 2021
@mkArtakMSFT
Copy link
Member

Thanks for contacting us. This is not currently supported. We're looking into improving this experience as part of #30290

@mkArtakMSFT
Copy link
Member

By the way, base64 encoding usage in your example is not optimal. We have a good article on about this: https://docs.microsoft.com/en-us/aspnet/core/blazor/images?view=aspnetcore-6.0

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Nov 29, 2021
@ghost ghost added the Status: Resolved label Nov 29, 2021
@pawelel
Copy link
Author

pawelel commented Nov 30, 2021

By the way, base64 encoding usage in your example is not optimal. We have a good article on about this: https://docs.microsoft.com/en-us/aspnet/core/blazor/images?view=aspnetcore-6.0

Thanks, I have some memory leak issues with base64 example, but also wanted to use only C# code and hoped, that will be possible (to avoid JS)

@ghost ghost locked as resolved and limited conversation to collaborators Dec 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-builtin-components Features related to the built in components we ship or could ship in the future ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

4 participants