Exemplo n.º 1
0
        public void UploadFileAsync(string filePath, StatusProgressChanged uploadProgressChanged, StatusChanged uploadCompleted)
        {
            if (CurrentSecret == null)
            {
                return;
            }

            var destinationPath = String.Format("/api/{0}/{1}", CurrentSecret, UrlHelper.GetFileName(filePath));
            var client          = new ProgressBugfixedWebClient((new FileInfo(filePath)).Length);

            client.Headers ["content-type"] = "application/octet-stream";
            client.Encoding = Encoding.UTF8;

            client.UploadProgressChanged += (sender, e) => {
                uploadProgressChanged(e);
            };
            client.UploadFileCompleted += (sender, e) => {
                uploadCompleted();
                if (e.Cancelled)
                {
                    Console.Out.WriteLine("Upload file cancelled.");
                    return;
                }

                if (e.Error != null)
                {
                    Console.Out.WriteLine("Error uploading file: {0}", e.Error.Message);
                    return;
                }

                var response = System.Text.Encoding.UTF8.GetString(e.Result);

                if (!String.IsNullOrEmpty(response))
                {
                }
            };
            Send(destinationPath);
            client.computeContentLength(filePath);
            client.UploadFileAsync(new Uri(SERVER + destinationPath), "POST", filePath);
        }
Exemplo n.º 2
0
        public void UploadFileAsync(string filePath, StatusProgressChanged uploadProgressChanged, StatusChanged uploadCompleted)
        {
            if (CurrentSecret == null)
                                return;

                        var destinationPath = String.Format ("/api/{0}/{1}", CurrentSecret, UrlHelper.GetFileName (filePath));
                        var client = new ProgressBugfixedWebClient ((new FileInfo(filePath)).Length);
                        client.Headers ["content-type"] = "application/octet-stream";
                        client.Encoding = Encoding.UTF8;

                        client.UploadProgressChanged += (sender, e) => {
                                uploadProgressChanged (e); };
                        client.UploadFileCompleted += (sender, e) => {
                                uploadCompleted ();
                                if (e.Cancelled) {
                                        Console.Out.WriteLine ("Upload file cancelled.");
                                        return;
                                }

                                if (e.Error != null) {
                                        Console.Out.WriteLine ("Error uploading file: {0}", e.Error.Message);
                                        return;
                                }

                                var response = System.Text.Encoding.UTF8.GetString (e.Result);

                                if (!String.IsNullOrEmpty (response)) {
                                }
                        };
                        Send (destinationPath);
                        client.computeContentLength(filePath);
                        client.UploadFileAsync (new Uri (SERVER + destinationPath), "POST", filePath);
        }