Skip to content

Blazor InputFile - Access IBrowserFile Stream after file list has changed #35178

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
MichelJansson opened this issue Aug 9, 2021 · 1 comment
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

Comments

@MichelJansson
Copy link
Contributor

MichelJansson commented Aug 9, 2021

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

I am trying to store a stack of IBrowserFiles (images) using one InputFile component (so the user can add one file after the other), where a preview is generated immediately onchange, and later when the user clicks submit/save we upload the entire stack to the server.
BUT there seem to be no way to access the IBrowserFile stream (OpenReadStream() throws) after the file list of the InputFile it originated from has changed.

This could be solved by also reading all the files into memory onchange, but would be very wasteful as I'm expecting up to 200 files.

Describe the solution you'd like

As long as I have a reference to the IBrowserFile in .NET I would like to be able to get it's stream just as I can in JS when keeping a reference to a File.

The changes implemented by @TanayParikh in #33986, looks like it MAY have opened up for an alternative solution to hold a reference to the stream by calling IBrowserFile.OpenReadStream (which returns a BrowserFileStream, which opens a stream via IJSStreamReference) before the file list changes. But I have no way of verifying this as that code has yet to be released, and I have a little hard time following all the interop stream code.

Additional context

This issue stems from that the original JS objects is stored in a list on the input element, which is cleared each time the file list is changed, and after that the blob I am hoping to stream is gone.

@javiercn javiercn added 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 labels Aug 9, 2021
@mkArtakMSFT
Copy link
Contributor

Thank you for contacting us. This will require custom logic to load the file into memory as soon as it's selected. We don't plan to bake this functionality into the framework at this time.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 8, 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
Projects
None yet
Development

No branches or pull requests

3 participants