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


C# MultipartFormDataContent.Dispose方法代码示例

本文整理汇总了C#中System.Net.Http.MultipartFormDataContent.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# MultipartFormDataContent.Dispose方法的具体用法?C# MultipartFormDataContent.Dispose怎么用?C# MultipartFormDataContent.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.MultipartFormDataContent的用法示例。


在下文中一共展示了MultipartFormDataContent.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadImageAsync

        public static async Task<string> UploadImageAsync(Image bitmap)
        {
            var memoryStream = new MemoryStream();  
            bitmap.Save(memoryStream, ImageFormat.Png);
            memoryStream.Seek(0, SeekOrigin.Begin);

            var streamContent = new StreamContent(memoryStream);
            streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/png");

            var multipartDataContent = new MultipartFormDataContent
            {
                {streamContent, "shot", "screenshot.png"}
            };

            var responseMessage = await _httpClient.PostAsync(API_URL, multipartDataContent);
            if (!responseMessage.IsSuccessStatusCode)
                return null;

            var responseString = await responseMessage.Content.ReadAsStringAsync();
            var json = _javaScriptSerializer.Deserialize<dynamic>(responseString);

            streamContent.Dispose();
            multipartDataContent.Dispose();
            if (json["result"] == ":(")
            {
                Console.WriteLine("Error!");
                Console.WriteLine(json["error"]["code"]);
                Console.WriteLine(json["error"]["message"]);
            }

            return json["link"];
        }
开发者ID:zwolsman,项目名称:lensert-win,代码行数:32,代码来源:LensertClient.cs

示例2: UploadExtensionLibraryAsync

        public void UploadExtensionLibraryAsync(string selectedFileName, byte[] fileContents, ObservableCollection<string> assemblies, object userState)
        {
            Uri uri = CreateRestRequest("Extensions/Upload");

            var assembliesString = assemblies != null ? string.Join(",", assemblies) : null;
            var content = new MultipartFormDataContent();
            var ms = new MemoryStream(fileContents);
            var fileContent = new StreamContent(ms);

            // Specify the content disposition and content type - without this the form data will not
            // be included in the Request object in .NET 2.0 app pools
            fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
            {
                Name = "\"files\"",
                FileName = "\"" + selectedFileName + "\""
            };
            fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-silverlight-app");
            content.Add(fileContent);
            
            var stringContent = new StringContent(assembliesString);

            // Need to specify the content disposition and content type for .NET 2.0 compatibility here, too
            stringContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
            {
                Name = "\"assemblies\""
            };
            stringContent.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
            content.Add(stringContent);

            var client = new HttpClient();
            client.PostAsync(uri, content).ContinueWith(t =>
            {
                stringContent.Dispose();
                fileContent.Dispose();
                ms.Dispose();
                content.Dispose();

                if (t.IsCanceled)
                    return;

                if (t.Exception != null)
                {
                    var errorDisplay = new ErrorDisplay();

                    // Attempt to get the stack trace with IL offsets
                    string stackTraceIL = t.Exception.StackTraceIL();

                    ErrorData data = new ErrorData()
                    {
                        Message = t.Exception.Message,
                        StackTrace = !string.IsNullOrEmpty(stackTraceIL) ? stackTraceIL :
                            t.Exception.StackTrace
                    };

                    errorDisplay.DataContext = data;

                    // Size the error UI
                    double width = Application.Current.RootVisual.RenderSize.Width * 0.67;
                    errorDisplay.Width = width > errorDisplay.MaxWidth ? errorDisplay.MaxWidth : width;
                    errorDisplay.Completed += (o, a) => BuilderApplication.Instance.HideWindow(errorDisplay);

                    // Show the error
                    BuilderApplication.Instance.ShowWindow(Strings.ErrorOccured, errorDisplay, false, null, null);
                }

                if (UploadExtensionLibraryCompleted != null)
                {
                    UploadExtensionLibraryCompleted(this, new UploadExtensionLibraryCompletedEventArgs()
                    {
                        Error = t.Exception,
                        UserState = userState,
                    });
                }

            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
开发者ID:Esri,项目名称:arcgis-viewer-silverlight,代码行数:76,代码来源:ApplicationBuilderClient.cs


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