private async Task <Image> UploadImageAsync(string imageString, ImageUploadMode mode, string album = null, string title = null, string description = null) { if (imageString == null) { throw new ArgumentNullException(nameof(imageString)); } ImageUploadParams img = new ImageUploadParams(imageString, album, null, title, description, mode); HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Post, "/3/image"); msg.Content = new StringContent(JsonConvert.SerializeObject(img)); msg.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); var response = await client.SendAsync(msg); (bool success, int status, string dataJson) = GetDataToken(await response.Content.ReadAsStringAsync()); if (success) { return(JsonConvert.DeserializeObject <Image>(dataJson)); } else { throw new ApiRequestException(dataJson) { Status = status }; } }
public ImageUploadParams(string image, string album, string name, string title, string description, ImageUploadMode mode) { Image = image ?? throw new ArgumentNullException(nameof(image)); Album = album; Name = name; Title = title; Description = description; if (mode == ImageUploadMode.Base64) { Type = "base64"; } else if (mode == ImageUploadMode.Url) { Type = "URL"; } }