I have a problem, I'm creating an app in net core, to upload kids information, but, the main problem is than all the image I have are from my phone and you know than we are talking about 9-15 MB per picture, so, I know than I can tell the user "There's a limitation" but, I thinks than that its not useful, so, There's a way to reduce the size of the image loosing the less quality possible?.
This is my Method
Class
public IFormFile ImageFile { get; set; }
Method
if (vm.ImageFile != null && vm.ImageFile.Length > 0)
{
var guid = Guid.NewGuid().ToString();
var file = $"{guid}.jpg";
path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\Kids", file);
using (var stream = new FileStream(path, FileMode.Create))
{
//var convertedImage = MagicSolutionGivenByTheAwsomeStackOverFlowCommunity
await vm.ImageFile.CopyToAsync(stream);
}
}
Layout
<form asp-action="Create" enctype="multipart/form-data">
<input type="hidden" asp-for="Imagen"/>
<div class="col-sm-4">
<label asp-for="Imagen" class="control-label"></label>
<div>
<input asp-for="ImageFile" class="form-control filestyle"
type="file" data-classbutton="btn btn-secondary"
data-classinput="form-control inline"
data-icon="<span class='fa fa-upload mr'></span>" />
</div>
<span asp-validation-for="Imagen" class="text-danger"></span>
</div>
</form>