Skip to content
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

Add a file upload component #12205

Closed
mkArtakMSFT opened this issue Jul 15, 2019 · 12 comments
Closed

Add a file upload component #12205

mkArtakMSFT opened this issue Jul 15, 2019 · 12 comments
Labels
area-blazor Includes: Blazor, Razor Components Components Big Rock This issue tracks a big effort which can span multiple issues Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one
Milestone

Comments

@mkArtakMSFT
Copy link
Member

mkArtakMSFT commented Jul 15, 2019

Introduce a component for file upload. We have a couple of examples of this including @SteveSandersonMS's sample here: http://blog.stevensanderson.com/2019/09/13/blazor-inputfile/

@mkArtakMSFT mkArtakMSFT added Needs: Design This issue requires design work before implementating. enhancement This issue represents an ask for new feature or an enhancement to an existing one area-blazor Includes: Blazor, Razor Components labels Jul 15, 2019
@mkArtakMSFT mkArtakMSFT added this to the 3.1.0 milestone Jul 15, 2019
@RemiBou
Copy link
Contributor

RemiBou commented Jul 16, 2019

It would be easier if there was a class that would handle the js interop. It's 20 LOC but I think it would be easier for everybody to have this built in instead of relying on 3rd party lib. I am not a big fan of builtin JS interop (like a full DOM interaction wrapper), but in this case it would be nice.

@conficient
Copy link
Contributor

conficient commented Jul 16, 2019

Agreed @RemiBou - I liked your blog article on this, by the way 🥇

This is almost "core" functionality and a lot of apps will want to do this, so it would be nice if there was a <UploadFile> component and the necessary JSinterop was embedded in either blazor.webassembly.js or blazor.server.js as appropriate. That way you don't have to import a package to do this.

It won't suit all use cases but those can be implemented custom packages and JSinterop as required.

@mkArtakMSFT mkArtakMSFT modified the milestones: 3.1.0, 5.0.0-alpha1 Aug 5, 2019
@ryanelian
Copy link

I love this library approach for uploading files to Blazor:

https://github.com/Tewr/BlazorFileReader

It turns file input into readable stream.

I think you guys can improve upon this concept by automatically streaming the input file into a temporary folder.

<form>
    <!-- File automagically gets uploaded when selected, streamed directly into a temporary file / folder transparently. Allow a progress bar for good measure. -->
    <input type="file" @bind-value="MyFile" @progress="PercentageProgress" />
</form>
@code {
    System.IO.FileStream MyFile { set; get; }
    double PercentageProgress { set; get; }
}

@rynowak
Copy link
Member

rynowak commented Sep 24, 2019

@SteveSandersonMS also made a thing http://blog.stevensanderson.com/2019/09/13/blazor-inputfile/

@etherealjoy
Copy link

etherealjoy commented Sep 26, 2019

@SteveSandersonMS also made a thing http://blog.stevensanderson.com/2019/09/13/blazor-inputfile/

I like this. I hope in the future you can take it forward and make it more intuitive and easy to use.
No fancy setup needed, it just works!

@mkArtakMSFT mkArtakMSFT changed the title How to upload files in Blazor Server App How to upload files in Blazor App Jan 10, 2020
@mkArtakMSFT mkArtakMSFT added the Components Big Rock This issue tracks a big effort which can span multiple issues label Jan 10, 2020
@pranavkm pranavkm modified the milestones: Next sprint planning, 5.0.0 Jun 18, 2020
@MackinnonBuck MackinnonBuck self-assigned this Jun 22, 2020
@mkArtakMSFT mkArtakMSFT modified the milestones: 5.0.0, 5.0.0-preview8 Jul 6, 2020
@GiantCrocodile
Copy link

It would be great if the new component is able to handle multiple files (min/max number of files) and not just a few MB but also bigger files. Drag & drop support would be nice to have.

@SteveSandersonMS
Copy link
Member

@GiantCrocodile If you get chance, please try out https://blog.stevensanderson.com/2019/09/13/blazor-inputfile/ and see if that meets your needs. It has the features you mentioned there. We are considering bringing this into the framework.

@GiantCrocodile
Copy link

GiantCrocodile commented Jul 16, 2020

@SteveSandersonMS Thank you for your reply. The mentioned example is one of the most relevant ones for me. I will try/use it for now but it has one or two minor issues I would like to see fixed/enhanced (see bug tracker at https://github.com/SteveSandersonMS/BlazorInputFile/issues). Thus it would be great if we have a solution like that in the official core. I'm sure you guys will do this properly. So far, I'm a newbie user of Blazor but heavily amazed!

Edit: Nevermind, I didn't notice that it's you @SteveSandersonMS; the guy behind that example. Thank you for your great work and the good article! Highly appreciated.

@etherealjoy
Copy link

@GiantCrocodile If you get chance, please try out https://blog.stevensanderson.com/2019/09/13/blazor-inputfile/ and see if that meets your needs. It has the features you mentioned there. We are considering bringing this into the framework.

I tried it, and I see it has been updated too :)
No more warnings. Many thanks for the effort.

@hultqvist
Copy link

Will this component pass through native file objects that can be passed on to an HTTP request?
As I understand it now the file is read and sent as bytes to the Blazor runtime.

For example when uploading a file, I rather not the content be read in memory of my app.

@SteveSandersonMS
Copy link
Member

@hultqvist No, that isn't what this new component is for. If you want to do a traditional HTTP upload, you don't need this new component. You can simply create an <input type=file> within a <form> that uploads to whatever HTTP endpoint you want.

@hultqvist
Copy link

@SteveSandersonMS I was thinking of something similar to the Javascript example below where the file is uploaded without reloading the page.

I was looking for a similar approach where the logic is managed with the rest of the C# code.

let photo = document.getElementById("image-file").files[0];
let formData = new FormData();
formData.append("photo", photo);
fetch('/upload/image', {method: "POST", body: formData});

@MackinnonBuck MackinnonBuck added Done This issue has been fixed and removed Working labels Aug 21, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Sep 29, 2020
@ghost ghost unassigned MackinnonBuck Sep 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components Components Big Rock This issue tracks a big effort which can span multiple issues Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one
Projects
None yet
Development

No branches or pull requests