public async Task <IActionResult> UploadImages([FromBody] UploadImagesModel model) { //Guid projectId = Guid.Parse("3a7bfe46-2fa2-4304-a4a7-b4bf54ee9ac3"); Guid projectId = Guid.Parse(model.ProjectId); List <Uri> lstImages = model.Items.Where(p => p.IsSelected == true).Select(p => new Uri(p.ImageUrl)).ToList(); var uploadImagesResult = await AzureCustomVisionService.UploadImagesAsync(lstImages, projectId); List <string> tags = new List <string>() { model.Tag }; foreach (var singleImage in uploadImagesResult) { try { await this.AzureCustomVisionService.CreateImageTagsAsync(projectId, singleImage.Image.Id, tags); await Task.Delay(TimeSpan.FromSeconds(1)); } catch (Exception ex) { this.Logger.LogError(ex, ex.Message); } } return(Ok()); }
public ActionResult SaveImages() { var model = new UploadImagesModel(); try { model.headFileName = Request.Form["headFileName"]; model.x = Convert.ToInt32(Request.Form["x"]); model.y = Convert.ToInt32(Request.Form["y"]); model.width = Convert.ToInt32(Request.Form["width"]); model.height = Convert.ToInt32(Request.Form["height"]); var filepath = Path.Combine(Server.MapPath(CustomerMediaPath), model.headFileName); var fileExt = Path.GetExtension(filepath); var orgFileName = Path.GetFileNameWithoutExtension(filepath); var path160 = Server.MapPath(CustomerMediaPath + "/160/"); if (!Directory.Exists(path160)) { Directory.CreateDirectory(path160); } var path100 = Server.MapPath(CustomerMediaPath + "/100/"); if (!Directory.Exists(path100)) { Directory.CreateDirectory(path100); } var fullPath160 = Path.Combine(path160, orgFileName + "_160" + fileExt); var fullPath100 = Path.Combine(path100, orgFileName + "_100" + fileExt); CutAvatarWithPadding(filepath, model.x, model.y, model.width, model.height, 75L, fullPath160, 210); CutAvatar(filepath, model.x, model.y, model.width, model.height, 75L, fullPath100, 100); var imgInfo = Image.FromFile(filepath); const long newId = 0; imgInfo.Dispose(); return(Json(new NBCMSResultJson { Status = StatusType.OK, Data = new { name = orgFileName, ext = fileExt, newID = newId } })); } catch (Exception ex) { NBCMSLoggerManager.Error(ex.Message); NBCMSLoggerManager.Error(ex.Source); return(Json(new NBCMSResultJson { Status = StatusType.Exception, Data = ex.Message })); } }