public async Task <ActionResult> UploadImage(IFormFile file) { string error = string.Empty; string retImageUrl = string.Empty; if (file == null || file.Length == 0 || !file.ContentType.Contains("image")) { error = "La imagen no es válida"; } else { var model = new SaveImageStreamCommand(); model.FileStream = file.OpenReadStream(); model.ImageLocation = ImageSaveLocationEnum.Uploads; model.SaveMaxSizes = ImageSizeEnum.Img900; var imageUrl = await _commandBus.Send(model); retImageUrl = await _queryBus.Send(new GetImagePathQuery(imageUrl, ImageSaveLocationEnum.Uploads, ImageSizeEnum.Img900)); } //para el upload de ckeditor utilizar siempre url completa if (!retImageUrl.StartsWith("http")) { var uri = await _queryBus.Send(new GetImageAbsoluteUriQuery()); retImageUrl = uri.ToString().TrimEnd('/') + retImageUrl; } return(Ok(new { url = retImageUrl, error })); }
public async Task <IActionResult> Post(IFormFile file, ImageSaveLocationEnum imageSaveLocation) { var model = new SaveImageStreamCommand(); model.FileStream = file.OpenReadStream(); model.ImageLocation = imageSaveLocation; //if (imageSaveLocation == ImageSaveLocationEnum.Profile) // model.CurrentUserId = User.GetUserId(); var imgGuid = await _commandBus.Send(model); return(Ok(imgGuid)); }