Imgur.API.Endpoints.Impl.ImageEndpoint.UploadImageBinaryAsync C# (CSharp) Method

UploadImageBinaryAsync() public method

Upload a new image using a binary file.
/// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// Thrown when an error is found in a response from an Imgur endpoint. Thrown when an error is found in a response from a Mashape endpoint.
public UploadImageBinaryAsync ( byte image, string albumId = null, string title = null, string description = null ) : Task
image byte A binary file.
albumId string /// The id of the album you want to add the image to. For anonymous albums, {albumId} should be the /// deletehash that is returned at creation. ///
title string The title of the image.
description string The description of the image.
return Task
        public async Task<IImage> UploadImageBinaryAsync(byte[] image, string albumId = null, string title = null,
            string description = null)
        {
            if (image == null)
                throw new ArgumentNullException(nameof(image));

            var url = "image";

            using (var request = RequestBuilder.UploadImageBinaryRequest(url, image, albumId, title, description))
            {
                var returnImage = await SendRequestAsync<Image>(request).ConfigureAwait(false);
                return returnImage;
            }
        }

Usage Example

コード例 #1
0
        public async Task UploadImageBinaryAsync_WithImage_AreEqual()
        {
            var client = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new ImageEndpoint(client);

            var file = File.ReadAllBytes("banana.gif");
            var image = await endpoint.UploadImageBinaryAsync(file, null, "binary test title!", "binary test desc!");

            Assert.IsFalse(string.IsNullOrEmpty(image.Id));
            Assert.AreEqual("binary test title!", image.Title);
            Assert.AreEqual("binary test desc!", image.Description);

            await GetImageAsync_WithImage_AreEqual(image);
            await UpdateImageAsync_WithImage_AreEqual(image);
            await DeleteImageAsync_WithImage_IsTrue(image);
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.ImageEndpoint::UploadImageBinaryAsync