private void UploadMediaItem_Click(object sender, EventArgs e) { OpenFileDialog fileSelector = new OpenFileDialog( ); if (fileSelector.ShowDialog( ) == DialogResult.OK) { PhotobucketNet.MediaItem newItem = Program.Instance.Photobucket.CreateCurrentUsersImageMediaItemFromFile(fileSelector.FileName); try { newItem.Title = "TEST265/asd f /asdf 43"; newItem.Description = "PLEASE /asdf/ as dONE MORE TIME"; _mediaItem = Program.Instance.Photobucket.UploadMediaItemToBaseAlbum(newItem); MessageBox.Show("UploadMediaItem Succeeded"); newItem.MediaStream.Close(); } catch (PhotobucketWebException) { MessageBox.Show("Network problems"); newItem.MediaStream.Close(); } catch (PhotobucketApiException apiEx) { MessageBox.Show("Error Code: " + apiEx.ErrorCode.ToString() + ": " + apiEx.ResponseMessage); newItem.MediaStream.Close(); } } }
public static MediaItem CreateFromUrl(string url) { return(MediaItem.CreateFromUrl(url, MediaType.Video)); }
public static MediaItem CreateFromFile(string username, string filepath) { return(MediaItem.CreateFromFile(username, filepath, MediaType.Video)); }
public override bool Equals(object obj) { MediaItem mediaItem = obj as MediaItem; return(Name.Equals(mediaItem.Name) && Type.Equals(mediaItem.Type) && Username.Equals(mediaItem.Username)); }
private XmlResponseMessage GetResponseForUploadMediaItem(string uploadMediaItemUrl, MediaItem mediaItem, QueryParameterList paramaters) { string boundary = "PHOTBUCKET_MIME_" + DateTime.Now.ToString("yyyyMMddhhmmss"); HttpWebRequest request = ( HttpWebRequest )HttpWebRequest.Create(uploadMediaItemUrl); //request.UserAgent = "Mozilla/4.0 PhotobucketNet API (compatible; MSIE 6.0; Windows NT 5.1)"; request.Method = "POST"; //request.KeepAlive = true; request.ContentType = "multipart/form-data; boundary=" + boundary + ""; //request.Expect = ""; StringBuilder sb = new StringBuilder(); foreach (QueryParameter paramater in paramaters) { if (paramater.Name == "format") { continue; } else if (paramater.Name == "oauth_signature") { paramater.Value = OAuth.UrlDecode(paramater.Value); } else if (paramater.Name == _description || paramater.Name == _title) { paramater.Value = OAuth.UrlDecode(paramater.Value); } sb.Append("--" + boundary + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"" + paramater.Name + "\"\r\n"); sb.Append("\r\n"); sb.Append(paramater.Value + "\r\n"); } sb.Append("--" + boundary + "\r\n"); sb.Append("Content-Disposition: form-data; name=\"uploadfile\"; filename=\"" + mediaItem.Name + "\"\r\n"); sb.Append("Content-Type: mimetype\r\nContent-Transfer-Ecoding: binary"); sb.Append("\r\n\r\n"); UTF8Encoding encoding = new UTF8Encoding(); byte[] postContents = encoding.GetBytes(sb.ToString()); byte[] photoContents = new byte[1]; using (Stream stream = mediaItem.MediaStream) { photoContents = new byte[stream.Length]; stream.Read(photoContents, 0, photoContents.Length); } byte[] postFooter = encoding.GetBytes("\r\n--" + boundary + "--\r\n"); byte[] dataBuffer = new byte[postContents.Length + photoContents.Length + postFooter.Length]; Buffer.BlockCopy(postContents, 0, dataBuffer, 0, postContents.Length); Buffer.BlockCopy(photoContents, 0, dataBuffer, postContents.Length, photoContents.Length); Buffer.BlockCopy(postFooter, 0, dataBuffer, postContents.Length + photoContents.Length, postFooter.Length); using (Stream resStream = request.GetRequestStreamAsync().Result) { int count = 1; int uploadBit = Math.Max(dataBuffer.Length / 100, 50 * 1024); int uploadSoFar = 0; if (OnUploadMediaProgress != null) { OnUploadMediaProgress(this, new UploadMediaProgressEventArgs(0, dataBuffer.Length)); } for (int i = 0; i < dataBuffer.Length; i = i + uploadBit) { int toUpload = Math.Min(uploadBit, dataBuffer.Length - i); uploadSoFar += toUpload; resStream.Write(dataBuffer, i, toUpload); if ((OnUploadMediaProgress != null) && ((count++) % 5 == 0 || uploadSoFar == dataBuffer.Length)) { OnUploadMediaProgress(this, new UploadMediaProgressEventArgs(uploadSoFar, dataBuffer.Length)); } } } try { request.Method = _uploadMediaMethod; HttpWebResponse response = ( HttpWebResponse )request.GetResponseAsync().Result; Stream responseStream = response.GetResponseStream(); return(new XmlResponseMessage(responseStream)); } catch (WebException webEx) { throw PhotobucketException.CreateFromWebException(webEx); } }
public MediaItem UploadMediaItemToBaseAlbum(MediaItem mediaItem) { Album baseAlbum = BaseAlbum; return(UploadMediaItemToAlbum(mediaItem, ref baseAlbum)); }
public MediaItem UploadMediaItemToAlbum(MediaItem mediaItem, Album album) { return(UploadMediaItemToAlbum(mediaItem, album.Path)); }