Click here to Skip to main content
15,880,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public IFormFile UploadedImage { get; set; }

<div class="form-group row">
            <label asp-for="UploadedImage" class="ml-2">Image</label>
            <input asp-for="UploadedImage" class="form-control" type="file"/>
            <span asp-validation-for="UploadedImage" class="text-danger"></span>

Currently user can upload anything, which will lead to awful things in backend.

Is there any easy straightforward way to allow uploading only images? Looking online some solutions look absolutely terrifying, but they are 5+ years old, so maybe .NET got better way to do it. Like [Image] attribute or something.

What I have tried:

I have some better or worse ideas, like trying to use System.Drawing library and catch exception, or using Mime-Detective, but I want to find better than worse solution. I don't know which ones are ok to use.
SeanChupas 14-May-21 16:33pm    
Is restricting based on file extension sufficient?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900