当前位置: 首页>>代码示例>>C#>>正文


C# IMediaItem.OpenRead方法代码示例

本文整理汇总了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);
                        }
                    }
                }
            }
开发者ID:opentween,项目名称:OpenTween,代码行数:36,代码来源:Mobypicture.cs

示例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);
                        }
                    }
                }
            }
        }
开发者ID:nezuku,项目名称:OpenTween,代码行数:28,代码来源:Imgur.cs

示例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);
                        }
                    }
                }
            }
开发者ID:opentween,项目名称:OpenTween,代码行数:34,代码来源:TwipplePhoto.cs


注:本文中的IMediaItem.OpenRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。