

The method accepts the posted file through the IFormFile interface. Resized.Save(imageStream, ImageFormat.Jpeg) Using var imageStream = new MemoryStream() Var resized = new Bitmap(image, new Size(256, 256))

Var image = Image.FromStream(file.OpenReadStream()) Public IActionResult Index(IFormFile file) Next, include a new endpoint in the HomeController class accepting the file post: By specifying file extensions in the accept attribute, I make sure that the user picks only image files. The enctype attribute needs to be set to multipart/form-data for the browser to include the file in the request. The form includes a file picker and a submit button. Include a form on the frontpage ( index.cshtml):

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. For this example I simply created a new ASP.NET Core MVC website from the default template. Let's start by including an upload form on an ASP.NET Core Razor Page. The WebImage class was never ported to ASP.NET Core, but there's still all of the graphics stuff in the System.Drawing namespace. It was a great helper when dealing with uploaded images on a website. The solution may not be so configurable as when using ImageSharp, but sufficient for simple scenarios.ĪSP.NET (classic) developers may remember the WebImage class. 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. I have blogged about upload and resizing with ASP.NET Core already: Upload and resize an image with ASP.NET Core and ImageSharp.
