I have blogged about upload and resizing with ASP.NET Core already: Upload and resize an image with ASP.NET Core and ImageSharp. With this post, I want to show a simple approach for uploading and resizing images with ASP.NET Core that doesn’t require any external libraries. The solution may not be so configurable as when using ImageSharp, but sufficient for simple scenarios.

ASP.NET (classic) developers may remember the WebImage class. It was a great helper when dealing with uploaded images on a website. The WebImage class was never ported to ASP.NET Core, but there’s still all of the graphics stuff in the System.Drawing namespace.

Let’s start by including an upload form on an ASP.NET Core Razor Page. For this example I simply created a new ASP.NET Core MVC website from the default template. The process has been documented multiple times on this blog already and Microsoft has a lot of examples too, why I don’t want to repeat it here. Include a form on the frontpage (index.cshtml):

<form method="post" enctype="multipart/form-data">
    <input type="file" name="file" accept=".png, .jpg, .jpeg, .gif" />
    <input type="submit" />
</form>

#aspdotnet core #aspdotnet

Upload and resize an image natively with ASP.NET Core
1.95 GEEK