public CollectionsConfig AddImage(string collectionId, byte[] imageData, string imageFileName, byte[] imageMetadata = null) { CollectionsConfig result = null; if (string.IsNullOrEmpty(collectionId)) { throw new ArgumentNullException(nameof(collectionId)); } if (imageData == null || string.IsNullOrEmpty(imageFileName)) { throw new ArgumentNullException("Image and image name required."); } string imageMimeType = GetImageMimeTypeFromFilename(imageFileName); try { var formData = new MultipartFormDataContent(); var imageDataContent = new ByteArrayContent(imageData); imageDataContent.Headers.ContentType = MediaTypeHeaderValue.Parse(imageMimeType); formData.Add(imageDataContent, "image_file", imageFileName); if (imageMetadata != null) { var imageMetadataContent = new ByteArrayContent(imageMetadata); imageMetadataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); formData.Add(imageMetadataContent, "metadata", "metadata.json"); } result = this.Client.PostAsync($"{ this.Endpoint}{string.Format(PATH_COLLECTION_IMAGES, collectionId)}") .WithArgument("version", VERSION_DATE_2016_05_20) .WithArgument("api_key", ApiKey) .WithBodyContent(formData) .As <CollectionsConfig>() .Result; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
private void OnAddImageToCollection(CollectionsConfig images, string customData) { if (images != null) { Log.Debug("TestVisualRecognition", "Add image to collection succeeded!"); m_CreatedCollectionImage = images.images[0].image_id; Log.Debug("TestVisualRecognition", "images processed: {0}", images.images_processed); foreach (CollectionImagesConfig image in images.images) { Log.Debug("TestVisualRecognition", "imageID: {0} | image_file: {1} | image metadata: {1}", image.image_id, image.image_file, image.metadata.ToString()); } } else { Log.Debug("TestVisualRecognition", "Add image to collection failed!"); } Test(images != null); m_AddImagesToCollectionTested = true; }