public IActionResult SavePastedImage([FromForm] IFormFile pastedImage) { const int MaxFileSize = 100 * 1024; // 100KB; var bytes = ConvertToBytes(pastedImage); if (bytes.Length > MaxFileSize) { return(BadRequest($"File is too big. Maximum size is {MaxFileSize} bytes.")); } if (!FileValidator.IsValidFileExtension(pastedImage.FileName, bytes, Array.Empty <byte>())) { return(BadRequest($"File data is not valid for the specified file format.")); } return(new JsonResult(new { // In a real-world situation, store the generated image somewhere - e.g. BlobStorage // and return the actual Url to it ImageUrl = "https://via.placeholder.com/150" })); }