Hi,
I have a problem with RadzenFileInput. I use the "Accept" property and set the Accept option with the value "application/xml", even if I set it to other MIME types it also accepts different file types. It works fine if we select the file from the file explorer. The explorer only shows valid format types. But if I drag any other file and drop it in the window, the application immediately dies.
Hi @JJablonski02,
The Accept property of RadzenFileInput maps to the accept attribute of the underlying <input type="file">
. All it does is to provide a hint to the browser when displaying a file picker:
The accept
attribute doesn't validate the types of the selected files; it provides hints for browsers to guide users towards selecting the correct file types. It is still possible (in most cases) for users to toggle an option in the file chooser that makes it possible to override this and select any file they wish, and then choose incorrect file types. Because of this, you should make sure that the accept
attribute is backed up by appropriate server-side validation.
Okay I get It. I thought that Accept property in this case validates file aswell. So am I able to validate incoming file? Now if I drag a jpg file, the application stops working. How to prevent this?
I recommend using RadzenUpload instead.
As can I see in example below you pass on upload/multiple endpoint.
<RadzenUpload @ref="upload" Auto="false" Multiple="true" Url="upload/multiple" Change=@(args => OnChange(args, "Manual Upload")) InputAttributes="@(new Dictionary<string,object>(){ { "aria-label", "select file" }})"
Progress=@(args => OnProgress(args, "Manual Upload")) class="w-100" />
Am I Able to read IFormFile by invoking a method in same file instead hitting to an Api ?
Yes. There is a demo for that - Upload client-side without Url.
1 Like