// Methods
 public PicasaUploadHttpFormContent(PicasaUploadHttpForm form)
 {
     this.Form        = form;
     this.boundary    = "xxxx" + PhpTime.ToString();
     this.ContentType =
         String.Format("multipart/related; boundary=\"{0}\"", boundary);
     boundary = "--" + boundary;
 }
Esempio n. 2
0
        /// <summary>
        ///  This does the real work of the plugin - uploading to Picasa.
        /// </summary>
        ///
        /// <remarks>
        ///   First upload the main image, and then place the raw
        ///   image URL onto the clipboard for easy reference/paste.
        /// </remarks>
        private void UploadImage()
        {
            Tracing.Trace("Picasa::{0:X8}::UploadImage", this.GetHashCode());

            try
            {
                var address =
                    GdataSession.Authenticate(PluginSettings.EmailAddress, "picasa");

                // reset this in case user has changed it in the authn dialog.
                PluginSettings.EmailAddress = address;

                var headers =
                    GdataSession.GetHeaders(PluginSettings.EmailAddress, "picasa");

                // user has declined or failed to authenticate
                if (headers == null)
                {
                    return;
                }

                // Now, upload the photo...
                var summaryText = GetSummaryText();

                var uploadform = new PicasaUploadHttpForm
                {
                    File    = this._fileName,
                    Summary = summaryText
                };

                var u = String.Format("/data/feed/api/user/default/albumid/{0}",
                                      PluginSettings.Album.Id);

                Tracing.Trace("Upload to album: {0} ({1})",
                              PluginSettings.Album.Name,
                              PluginSettings.Album.Id);

                var uri = new Uri(u, UriKind.RelativeOrAbsolute);

                // POST the request
                using (var requestMsg =
                           new HttpRequestMessage("POST",
                                                  uri,
                                                  headers,
                                                  uploadform.CreateHttpContent()))
                {
                    using (var picasa = new HttpClient(_basePicasaUrl))
                    {
                        var response = picasa.Send(requestMsg);
                        response.EnsureStatusIsSuccessful();
                        var    foo         = response.Content.ReadAsXmlSerializable <UploadResponse>();
                        string rawImageUri = foo.content.mediaUrl;
                        if (PluginSettings.PopBrowser)
                        {
                            System.Diagnostics.Process.Start(rawImageUri);
                        }
                        Clipboard.SetDataObject(rawImageUri, true);
                    }
                }

                Tracing.Trace("all done.");
                Tracing.Trace("---------------------------------");
            }
            catch (Exception exc1)
            {
                Tracing.Trace("Exception. {0}", exc1.Message);
                Tracing.Trace("{0}", exc1.StackTrace);

                Tracing.Trace("---------------------------------");
                MessageBox.Show("There's been an exception uploading your image:" +
                                Environment.NewLine +
                                exc1.Message +
                                Environment.NewLine +
                                Environment.NewLine +
                                "You will have to upload this file manually: " +
                                Environment.NewLine +
                                this._fileName,
                                "Cropper Plugin for Picasa",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            return;
        }