I am making a page in asp.net core that is uploading images to server using input type file html control.
<form method="post" asp-action="Add" enctype="multipart/form-data">
<input type="file" name="mediaUpload" />
<button type="submit">Submit</button>
</form>
I have also added the System.Drawing for .NET Core dll from NuGet.
Now on my post action I want to get the image Width & Height. This is the below code for it (but its now working).
[HttpPost]
public ActionResult Add(IFormFile mediaUpload)
{
Image image = Image.FromStream(file.OpenReadStream); // error is here
int width = image.Width;
int height = image.Height;
}
The complile time error -
Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'method group' to 'Stream' Goldentaurus E:\Website\Goldentaurus\Goldentaurus\Controllers\MediaController.cs 453 Active
Please help??
Note: My previous ASP.NET MVC 5 application(code shown below) was using a similar code that was working very well. I modified it to the above code to work on asp.net core.
[HttpPost]
public ActionResult Add(HttpPostedFileBase mediaUpload)
{
Image image = Image.FromStream(file.InputStream);
int width = image.Width;
int height = image.Height;
}
OpenReadStreamis a function, so you need to add()to invoke it.