本文整理汇总了C#中IMediaItem.OpenRead方法的典型用法代码示例。如果您正苦于以下问题:C# IMediaItem.OpenRead方法的具体用法?C# IMediaItem.OpenRead怎么用?C# IMediaItem.OpenRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMediaItem
的用法示例。
在下文中一共展示了IMediaItem.OpenRead方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadFileAsync
/// <summary>
/// 画像のアップロードを行います
/// </summary>
/// <exception cref="WebApiException"/>
/// <exception cref="XmlException"/>
public async Task<XDocument> UploadFileAsync(IMediaItem item, string message)
{
// 参照: http://developers.mobypicture.com/documentation/2-0/upload/
using (var request = new HttpRequestMessage(HttpMethod.Post, UploadEndpoint))
using (var multipart = new MultipartFormDataContent())
{
request.Content = multipart;
using (var apiKeyContent = new StringContent(ApplicationSettings.MobypictureKey))
using (var messageContent = new StringContent(message))
using (var mediaStream = item.OpenRead())
using (var mediaContent = new StreamContent(mediaStream))
{
multipart.Add(apiKeyContent, "key");
multipart.Add(messageContent, "message");
multipart.Add(mediaContent, "media", item.Name);
using (var response = await this.http.SendAsync(request).ConfigureAwait(false))
{
var responseText = await response.Content.ReadAsStringAsync()
.ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
throw new WebApiException(response.StatusCode.ToString(), responseText);
return XDocument.Parse(responseText);
}
}
}
}
示例2: UploadFileAsync
public async Task<XDocument> UploadFileAsync(IMediaItem item, string title)
{
using (var content = new MultipartFormDataContent())
using (var mediaStream = item.OpenRead())
using (var mediaContent = new StreamContent(mediaStream))
using (var titleContent = new StringContent(title))
{
content.Add(mediaContent, "image", item.Name);
content.Add(titleContent, "title");
using (var request = new HttpRequestMessage(HttpMethod.Post, UploadEndpoint))
{
request.Headers.Authorization =
new AuthenticationHeaderValue("Client-ID", ApplicationSettings.ImgurClientID);
request.Content = content;
using (var response = await Networking.Http.SendAsync(request).ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
return XDocument.Load(stream);
}
}
}
}
}
示例3: UploadFileAsync
/// <summary>
/// 画像のアップロードを行います
/// </summary>
/// <exception cref="WebApiException"/>
/// <exception cref="XmlException"/>
public async Task<XDocument> UploadFileAsync(IMediaItem item)
{
// 参照: http://p.twipple.jp/wiki/API_Upload2/ja
using (var request = new HttpRequestMessage(HttpMethod.Post, UploadEndpoint))
using (var multipart = new MultipartFormDataContent())
{
request.Content = multipart;
using (var uploadFromContent = new StringContent(Application.ProductName))
using (var mediaStream = item.OpenRead())
using (var mediaContent = new StreamContent(mediaStream))
{
multipart.Add(uploadFromContent, "upload_from");
multipart.Add(mediaContent, "media", item.Name);
using (var response = await this.http.SendAsync(request).ConfigureAwait(false))
{
var responseText = await response.Content.ReadAsStringAsync()
.ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
throw new WebApiException(response.StatusCode.ToString(), responseText);
return XDocument.Parse(responseText);
}
}
}
}