Skip to content

Image file upload missing content type #25679

@danroth27

Description

@danroth27

When I try out the new InputFile component in .NET 5 RC1 to upload some image files, the uploaded IBrowserFIle instances are missing the content type.

Repro steps:

  • Install .NET 5 SDK 5.0.100-rc.1.20452.10
<InputFile OnChange="OnInputFileChange" multiple/>

<div class="image-list">
    @foreach (var imageDataUrl in imageDataUrls)
    {
        <img src="@imageDataUrl" />
    }
</div>

@code {
    IList<string> imageDataUrls = new List<string>();

    async Task OnInputFileChange(InputFileChangeEventArgs e)
    {
        // Inspect the content types here when uploading some images files
        // Expected: image content types, Actual: no content type.
        var imageFiles = e.GetMultipleFiles();// .Where(file => file.ContentType.StartsWith("image/"));

        var format = "image/png";
        foreach (var imageFile in imageFiles)
        {
            var resizedImageFile = await imageFile.RequestImageFileAsync(format, 100, 100);
            var buffer = new byte[resizedImageFile.Size];
            await resizedImageFile.OpenReadStream().ReadAsync(buffer);
            var imageDataUrl = $"data:{format};base64,{Convert.ToBase64String(buffer)}";
            imageDataUrls.Add(imageDataUrl);
        }
    }
}

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions