Wie kann die Größe eines hochgeladenen Bildes in MVC 6 am besten angepasst werden? Ich möchte mehrere Varianten eines Bildes speichern (z. B. klein, groß usw.), um auszuwählen, welche später angezeigt werden sollen.Größe des hochgeladenen Bildes in MVC 6 ändern
Hier ist mein Code für die Aktion.
[HttpPost]
public async Task<IActionResult> UploadPhoto()
{
if (Request.Form.Files.Count != 1)
return new HttpStatusCodeResult((int)HttpStatusCode.BadRequest);
IFormFile file = Request.Form.Files[0];
// calculate hash
var sha = System.Security.Cryptography.SHA256.Create();
byte[] hash = sha.ComputeHash(file.OpenReadStream());
// calculate name and patch where to store the file
string extention = ExtentionFromContentType(file.ContentType);
if (String.IsNullOrEmpty(extention))
return HttpBadRequest("File type not supported");
string name = WebEncoders.Base64UrlEncode(hash) + extention;
string path = "uploads/photo/" + name;
// save the file
await file.SaveAsAsync(this.HostingEnvironment.MapPath(path));
}
Danke! Genau das, was ich brauche! –
@Phill Großartiger Link, danke, das Einzige, was ich für vNext Image gefunden habe. Aber ist die "neue Größe" der System.Drawing-Teil? – Alex
@voo das aktuelle Nuget erfordert weiterhin System.Drawing, aber die API ändert sich, damit V2 diese Einschränkung löscht. https://github.com/JimBobSquarePants/ImageProcessor#api-changes – Phill