-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Comments
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. |
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 It won't suit all use cases but those can be implemented custom packages and JSinterop as required. |
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; }
} |
I like this. I hope in the future you can take it forward and make it more intuitive and easy to use. |
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. |
@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. |
@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. |
I tried it, and I see it has been updated too :) |
Will this component pass through native file objects that can be passed on to an HTTP request? For example when uploading a file, I rather not the content be read in memory of my app. |
@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 |
@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}); |
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/
The text was updated successfully, but these errors were encountered: