Skip to content

InputFile Improvements #34040

@cedwards-telis

Description

@cedwards-telis

I'm trying to clear the list of files displayed by the component after the files are uploaded but the component provides no means of doing so (at least as far as I could find).

<InputFile OnChange="(e) => selectedFiles = e.GetMultipleFiles().ToList()" multiple />

<button @onclick="@SaveWholeForm()">Save</button>

@code {

List<IBrowserFile> selectedFiles;

void SaveWholeForm() {

        // save stuff
        using var content = new MultipartFormDataContent();

        foreach (var file in selectedFiles)
        {
            var fileContent = new StreamContent(file.OpenReadStream(1024 * 1024 * 100));

            content.Add(
                content: fileContent,
                name: "\"files\"",
                fileName: file.Name
                );
        }
        await httpClient.PostAsync($"/api/File/{Id}", content);
        // Need to clear the file list in some way
    }
}

I'd prefer it if the collection of files could be bound to a c# List or Array so it could be cleared or otherwise manipulated. Obviously I can use javascript but this feels like a workaround.

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor Components

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions