public IEnumerable <Label> GetBoundingBoxes(Topic topic, string imageId) { #region validation if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (string.IsNullOrEmpty(imageId)) { throw new ArgumentNullException(nameof(imageId)); } #endregion var modelId = LoadModel(); MultipartFormDataContent multipartFormDataContent = new MultipartFormDataContent(); using (Stream imageFileStream = ImageFileRepository.GetImageFile(topic, imageId)) { multipartFormDataContent.AddFileAsByteContent(imageFileStream, "image", imageId); } multipartFormDataContent.Add(new StringContent(modelId), "model"); HttpClient httpClient = HttpClientFactory.GetInferenceContainerHttpClient(); Uri uri = UriUtil.GetUri(httpClient.BaseAddress, "detect"); using MemoryStream memoryStream = new MemoryStream(httpClient.PostReadByteArray(uri, multipartFormDataContent)); using StreamReader streamReader = new StreamReader(memoryStream); return(ParseLabelResult(streamReader.ReadToEnd())); }
/// <summary> /// Add stream as byte array respresentation to multiparform data content of request. /// </summary> /// <param name="formDataContent">Multipartformdata content to add file to</param> /// <param name="fileStream">Stream of file to add to content</param> /// <param name="parameterName">Name of parameter which is used to consume file</param> /// <param name="fileName">Name of file (used for content type determination)</param> public static void AddFileAsByteContent(this MultipartFormDataContent formDataContent, Stream fileStream, string parameterName, string fileName) { #region validation if (fileStream == null) { throw new ArgumentNullException(nameof(fileStream)); } if (string.IsNullOrEmpty(parameterName)) { throw new ArgumentNullException(nameof(parameterName)); } if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } #endregion byte[] byteContent = fileStream.ConvertToByteArray(); formDataContent.AddFileAsByteContent(byteContent, parameterName, fileName); }