0

I want to reduce the image size when I uploaded to a server.

View

@using (Html.BeginForm("UserCUD", "User", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="form-group col-md-3">
        <label id="lblImage" for="userImage">Image</label>
        <input type="file" class="form-control-file" value="Image" title=" " id="userImage" name="userImage" accept=".jpg">
    </div>
}

In my controller this is thw way I manipulate the image

Controller

public ActionResult UserCUD(FormCollection collection, HttpPostedFileBase userImage)
{
    if (userImage != null)
    {
        string pic = System.IO.Path.GetFileName(SOMEID);
        string path = System.IO.Path.Combine(Server.MapPath("~/Img/Users"), pic);

        userImage.SaveAs(path);
        using (MemoryStream ms = new MemoryStream())
        {
            userImage.InputStream.CopyTo(ms);
            byte[] array = ms.GetBuffer();
        }
    }   
}
  • SOMEID = Is a User ID that I give to the file name
  • I use FormCollection collection because I manipulate some other data

Question

Is there a way to reduce the image size IF this is really heavy/big?

Abner P
  • 53
  • 7

0 Answers0