public Result ValidateCreateModel(MobileSpecCreateDto dto) { try { byte[] bytes = Convert.FromBase64String(dto.Base64Image); MemoryStream fileStream = new MemoryStream(bytes); } catch (Exception e) { return(new Result { IsValid = false, ErrorMessage = e.Message }); } return(new Result { IsValid = true }); }
public IActionResult Create(MobileSpecCreateDto mobileSpecDto) { var validationResult = _validation.ValidateCreateModel(mobileSpecDto); var hash = Helper.ReturnUniqueValue(DateTime.Now, ""); if (!validationResult.IsValid) { return(UnprocessableEntity(validationResult.ErrorMessage)); } var mobileSpec = _mapper.Map <MobileSpec>(mobileSpecDto); var imageUrl = Url.ActionLink("GetImage", "Helper", new { imagename = $"{hash}.png" }); mobileSpec.ImageUrl = imageUrl; var res = _mobileSpecService.Add(mobileSpec); var bytes = Convert.FromBase64String(mobileSpecDto.Base64Image); MemoryStream fileStream = new MemoryStream(bytes); _minioProvider.UploadImage(hash, fileStream, "uploads", "png"); return(CreatedAtAction(nameof(Get), new { id = res.Id }, res.Id)); }