/// <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); } }
/// <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); } }