public async Task AddImageAsync([FromQuery] ImageAddRequest model, [Required] IFormFile formFile) { var imageContent = _imageService.HandleFile(formFile, model.RuleContentId); var requestModel = _mapper.Map <ImageAddRequest, FileCreateRequest>(model, opt => opt.AfterMap((src, dest) => { dest.Type = formFile.ContentType; dest.Name = formFile.FileName; dest.Content = imageContent; })); CampaignServiceErrorResponseModel response; try { response = await _campaignsClient.BurnRules.AddImage(requestModel); } catch (ClientApiException exception) { throw new ValidationApiException(exception.ErrorResponse); } ThrowIfError(response.ErrorCode, response.ErrorMessage); }
public async Task <ActionResult> UploadFileAsync(int locationId) { try { List <ImageAddRequest> files = new List <ImageAddRequest>(); foreach (var file in Request.Form.Files) { ImageAddRequest req = new ImageAddRequest(); req.Stream = new MemoryStream(); await file.CopyToAsync(req.Stream); req.Stream.Position = 0; req.Filename = file.FileName; files.Add(req); } return(Json(await _locationPhotoService.AddPhotosAsync(files, locationId))); } catch (System.Exception) { return(Json(new List <ServiceLocationPhotoViewModel>())); } }
/// <summary> /// Add an image into the Image list /// </summary> /// <param name="imageContent">Image Content</param> /// <param name="labels">Image labels</param> /// <returns>Immage add result</returns> public async Task <ImageAddResult> ImageAddAsync(ImageModeratableContent imageContent) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(this.options.HostUrl); //string urlPath = $"{this.options.ImageServiceCustomListPath}{"/Image/Add"}"; string urlPath = string.Format("{0}/Image/Add", this.options.ImageServiceCustomListPath); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, urlPath); ServiceHelpers.Addkey(message, this.options.ImageServiceCustomListKey); ImageAddRequest request = new ImageAddRequest(imageContent); if (imageContent.BinaryContent == null) { message.Content = new StringContent( JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); } else { message.Content = new StreamContent(imageContent.BinaryContent.Stream); message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(imageContent.BinaryContent.ContentType); } return(await ServiceHelpers.SendRequest <ImageAddResult>(client, message)); } }
/// <summary> /// Add an image into the Image list /// </summary> /// <param name="imageContent">Image Content</param> /// <param name="tag">Image policies</param> /// <param name="label">Image description</param> /// <returns>Immage add result</returns> public async Task <ImageAddResult> ImageAddAsync(ImageModeratableContent imageContent, string tag, string label) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(this.options.HostUrl); string queryParam = string.IsNullOrWhiteSpace(tag) ? string.Empty : "?tag=" + tag; if (string.IsNullOrWhiteSpace(queryParam)) { queryParam = string.IsNullOrWhiteSpace(label) ? string.Empty : "?label=" + label; } else { queryParam = queryParam + "&label=" + label; } //string urlPath = $"{this.options.ImageServiceCustomListPathV2}{"/Add"}"; //string urlPath = $"{this.options.ImageServiceCustomListPathV2}{string.Format("/Image/Add{0}", string.IsNullOrWhiteSpace(queryParam) ? string.Empty : queryParam)}"; string urlPath = string.Format("{0}/Image/Add{1}", this.options.ImageServiceCustomListPathV2, string.IsNullOrWhiteSpace(queryParam) ? string.Empty : queryParam); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, urlPath); ServiceHelpers.Addkey(message, this.options.ImageServiceCustomListKey); ImageAddRequest request = new ImageAddRequest(imageContent); if (imageContent.BinaryContent == null) { message.Content = new StringContent( JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); } else { message.Content = new StreamContent(imageContent.BinaryContent.Stream); message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(imageContent.BinaryContent.ContentType); } return(await ServiceHelpers.SendRequest <ImageAddResult>(client, message)); } }