ImgurNet.ApiEndpoints.ImageEndpoint.UploadImageFromBinaryAsync C# (CSharp) Method

UploadImageFromBinaryAsync() public method

public UploadImageFromBinaryAsync ( byte imageBinary, string albumId = null, string name = null, string title = null, string description = null ) : Task>
imageBinary byte
albumId string
name string
title string
description string
return Task>
		public async Task<ImgurResponse<Image>> UploadImageFromBinaryAsync(byte[] imageBinary,
			string albumId = null, string name = null, string title = null, string description = null)
		{
			if (ImgurClient.Authentication == null)
				throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");

			var keyPairs = new Dictionary<string, string>();
			if (albumId != null) keyPairs.Add(albumId, albumId);
			if (name != null) keyPairs.Add("name", name);
			if (title != null) keyPairs.Add("title", title);
			if (description != null) keyPairs.Add("description", description);
			var stream = new StreamContent(new MemoryStream(imageBinary));

			return await Request.SubmitImgurRequestAsync<Image>(Request.HttpMethod.Post, UploadImageUrl, ImgurClient.Authentication, keyPairs, stream);
		}

Usage Example

		public async Task TestCreateAlbum()
		{
			var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();
			var albumEndpoint = new AlbumEndpoint(imgurClient);
			var imageEndpoint = new ImageEndpoint(imgurClient);

			var filePath = VariousFunctions.GetTestsAssetDirectory() + @"\upload-image-example.jpg";
			var imageBinary = File.ReadAllBytes(filePath);

			var title = String.Format("dicks-{0}", new Random().Next(100, 1337));
			var description = String.Format("black dicks, yo-{0}", new Random().Next(100, 1337));

			var uploadedImages = new List<Image>();
			for (var i = 0; i < 2; i++)
				uploadedImages.Add((await imageEndpoint.UploadImageFromBinaryAsync(imageBinary)).Data);
			var createdAlbum = await albumEndpoint.CreateAlbumAsync(uploadedImages.ToArray(), uploadedImages[0], title, description);

			// Assert the Reponse
			Assert.IsNotNull(createdAlbum.Data);
			Assert.AreEqual(createdAlbum.Success, true);
			Assert.AreEqual(createdAlbum.Status, HttpStatusCode.OK);

			// Assert the data
			Assert.AreEqual(createdAlbum.Data.Title, title);
			Assert.AreEqual(createdAlbum.Data.Description, description);
		}
All Usage Examples Of ImgurNet.ApiEndpoints.ImageEndpoint::UploadImageFromBinaryAsync