public string uploadImageToGoogle(string path, string username, string password, string blogId) { if (!System.IO.File.Exists(path)) { return("Error! Image file not found"); } ///////////////////////token session and shits.../////////// PicasaService service = new PicasaService("HowToFixPRO"); service.setUserCredentials(username, password); /////////////////cdefault album is dropBox or something//// Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(username)); System.IO.FileInfo fileInfo = new System.IO.FileInfo(path); System.IO.FileStream fileStream = fileInfo.OpenRead(); PicasaEntry entry = (PicasaEntry)service.Insert(postUri, fileStream, "image/png", "nameOfYourFile"); fileStream.Close(); PhotoAccessor ac = new PhotoAccessor(entry); string contentUrl = entry.Media.Content.Attributes["url"] as string; return(contentUrl); }
public Picture AddPictureToAlbum(string albumID, Stream image, string imageName, string title, string description, DateTime?positionDateTime, Position position) { var service = new PicasaService(PicasaConfiguration.Settings.Application.Name); service.setUserCredentials(PicasaConfiguration.Settings.Authentication.Username, PicasaConfiguration.Settings.Authentication.Password); var postUri = new Uri(PicasaQuery.CreatePicasaUri(PicasaConfiguration.Settings.Authentication.Username, albumID)); var entry = (PicasaEntry)service.Insert(postUri, image, "image/jpeg", imageName); entry.Title.Text = title; entry.Summary.Text = description; if (positionDateTime != null) { entry.SetPhotoExtensionValue("timestamp", Convert.ToTimestamp(positionDateTime.Value)); } if (position != null) { entry.Location = new GeoRssWhere(); entry.Location.Latitude = position.Latitude; entry.Location.Longitude = position.Longitude; } entry = (PicasaEntry)entry.Update(); return(PicasaDataMapper.MapPicasaImage(entry)); }
static void Main(string[] args) { while (true) { try { string[] filePaths = Directory.GetFiles(@"C:\WeddApp\upload"); DateTime current = new DateTime(); for (int i = 0; i < filePaths.Length; i++) { PicasaService myPicasa = new PicasaService("Vikash-Test-Picasa"); //Passing GMail credentials(EmailID and Password) myPicasa.setUserCredentials("*****@*****.**", "0542686874"); //User ID and AlbumID has been used to create new URL Uri newURI = new Uri(PicasaQuery.CreatePicasaUri("hagit.oded", "5780002529047522017")); //Image path which we are uploading current = DateTime.Now; System.IO.FileInfo newFile = new System.IO.FileInfo(filePaths[i]); System.IO.FileStream neFStream = newFile.OpenRead(); PicasaEntry newEntry = (PicasaEntry)myPicasa.Insert(newURI, neFStream, "Image/jpeg", Convert.ToString(current)); Console.Out.WriteLine("Image " + newFile.Name + " uploaded"); neFStream.Close(); File.Delete(filePaths[i]); } Thread.Sleep(ts); } catch (Exception ex) { Console.Out.WriteLine(ex.Message); System.Diagnostics.EventLog.WriteEntry("WeddApp", ex.Message, System.Diagnostics.EventLogEntryType.Error, 626); } } }
public void on_Click(object sender, DirectEventArgs e) { if (Session["service"] != null && Session["user"] != null) { //String name = ComboBox1.SelectedItem.Value; string path = this.FileUploadField1.FileName; path = Server.MapPath(path); User u = Session["user"] as User; Uri postUri = new Uri(PicasaQuery.CreatePicasaUri("diegoturciostc", "5680246730142935889")); System.IO.Stream fileInfo = this.FileUploadField1.PostedFile.InputStream; int buffer = 1024 * 1024; System.IO.FileStream filestream = null;//new System.IO.FileStream(path, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write); filestream = System.IO.File.Create(path); filestream.SetLength(fileInfo.Length); int bytesRead = -1; byte[] bytes = new byte[buffer]; while ((bytesRead = fileInfo.Read(bytes, 0, buffer)) > 0) { filestream.Write(bytes, 0, bytesRead); } PicasaService tmp = Session["service"] as PicasaService; PicasaEntry entry = (PicasaEntry)tmp.Insert(postUri, filestream, "image/jpeg", path); filestream.Close(); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } }
public void UploadPhoto(Site e, IEnumerable <HttpPostedFileBase> files, string[] noteList) { if (files == null || files.Count() == 0 || files.Where(r => r != null).Count() == 0) { return; } PicasaService service = InitPicasaService(); if (string.IsNullOrEmpty(e.AlbumUrl)) { e.AlbumUrl = CreateAlbum(e.ID.ToString()); } Uri postUri = new Uri(e.AlbumUrl.Replace("entry", "feed")); for (int i = 0; i < files.Count(); i++) { var item = files.ElementAt(i); if (item != null) { DateTime?takenDate = GetMetadata_TakenDate(item); MemoryStream mStream = new MemoryStream(); item.InputStream.Position = 0; item.InputStream.CopyTo(mStream); mStream.Position = 0; //PicasaEntry entry = (PicasaEntry)service.Insert(postUri, mStream, "image/jpeg", ""); //PicasaEntry entry = (PicasaEntry)service.Insert(postUri, item.InputStream, "image/jpeg", ""); //photoUriList.Add(entry.Media.Content.Url); PicasaEntry entry = new PhotoEntry(); entry.MediaSource = new Google.GData.Client.MediaFileSource(mStream, Path.GetFileName(item.FileName), "image/jpeg"); entry.Title = new AtomTextConstruct(AtomTextConstructElementType.Title, noteList[i]); entry.Summary = new AtomTextConstruct(AtomTextConstructElementType.Summary, noteList[i]); //service.InsertAsync(postUri, entry, new { SiteID = e.ID, AM = asyncManager }); PicasaEntry createdEntry = service.Insert(postUri, entry); if (createdEntry != null) { SitePhoto photo = new SitePhoto(); photo.Url = createdEntry.Media.Content.Url; photo.AtomUrl = createdEntry.EditUri.Content; photo.TakenDate = takenDate; photo.Note = noteList[i]; e.SitePhotoes.Add(photo); } } } }
/// <summary> /// Do the actual upload to Picasa /// For more details on the available parameters, see: http://code.google.com/apis/picasaweb/docs/1.0/developers_guide_dotnet.html /// </summary> /// <param name="imageData">byte[] with image data</param> /// <returns>PicasaResponse</returns> public static PicasaInfo UploadToPicasa(byte[] imageData, string title, string filename, string contentType) { PicasaService service = new PicasaService(Picasa_APPLICATION_NAME); service.setUserCredentials(config.Username, config.Password); Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(config.Username)); // build the data stream Stream data = new MemoryStream(imageData); PicasaEntry entry = (PicasaEntry)service.Insert(postUri, data, contentType, filename); return(RetrievePicasaInfo(entry)); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>tries to insert a photo using MIME multipart</summary> ////////////////////////////////////////////////////////////////////// [Test] public void InsertMimePhotoTest() { Tracing.TraceMsg("Entering InsertMimePhotoTest"); AlbumQuery query = new AlbumQuery(); PicasaService service = new PicasaService("unittests"); if (this.defaultPhotosUri != null) { if (this.userName != null) { service.Credentials = new GDataCredentials(this.userName, this.passWord); } query.Uri = new Uri(this.defaultPhotosUri); PicasaFeed feed = service.Query(query); if (feed != null) { Assert.IsTrue(feed.Entries != null, "the albumfeed needs entries"); Assert.IsTrue(feed.Entries[0] != null, "the albumfeed needs at least ONE entry"); PicasaEntry album = feed.Entries[0] as PicasaEntry; PhotoEntry newPhoto = new PhotoEntry(); newPhoto.Title.Text = "this is a title"; newPhoto.Summary.Text = "A lovely shot in the ocean"; newPhoto.MediaSource = new MediaFileSource(this.resourcePath + "testnet.jpg", "image/jpeg"); Uri postUri = new Uri(album.FeedUri.ToString()); PicasaEntry entry = service.Insert(postUri, newPhoto) as PicasaEntry; Assert.IsTrue(entry.IsPhoto, "the new entry should be a photo entry"); entry.Title.Text = "This is a new Title"; entry.Summary.Text = "A lovely shot in the shade"; entry.MediaSource = new MediaFileSource(this.resourcePath + "testnet.jpg", "image/jpeg"); PicasaEntry updatedEntry = entry.Update() as PicasaEntry; Assert.IsTrue(updatedEntry.IsPhoto, "the new entry should be a photo entry"); Assert.IsTrue(updatedEntry.Title.Text == "This is a new Title", "The titles should be identical"); Assert.IsTrue(updatedEntry.Summary.Text == "A lovely shot in the shade", "The summariesa should be identical"); } } }
public string CreateAlbum(string name, bool isBackup = false) { PicasaService service = InitPicasaService(); AlbumEntry newEntry = new AlbumEntry(); newEntry.Title.Text = name + (isBackup ? "B" : ""); newEntry.Summary.Text = newEntry.Title.Text; Uri feedUri = new Uri(PicasaQuery.CreatePicasaUri(OAMSSetting.GoogleUsername)); PicasaEntry createdEntry = (PicasaEntry)service.Insert(feedUri, newEntry); //5507469898148065681 return(createdEntry.EditUri.Content); //return createdEntry.Id.AbsoluteUri; }
public void UploadPhotoTo(string albumId, string filename) { var service = new PicasaService("GPhotoSync"); service.SetAuthenticationToken(_credentials.AccessToken); var query = new PhotoQuery(PicasaQuery.CreatePicasaUri(_credentials.User, albumId)); var feed = service.Query(query); var media = new MediaFileSource(filename, MimeTypes.GetMimeType(Path.GetExtension(filename))); var photo = new PhotoEntry(); photo.Title = new AtomTextConstruct { Text = Path.GetFileNameWithoutExtension(filename) }; photo.MediaSource = media; service.Insert(feed, photo); }
public void UploadPhotoToBackupAlbum(Site e, Stream stream) { PicasaService service = InitPicasaService(); if (string.IsNullOrEmpty(e.BackupAlbumUrl)) { e.BackupAlbumUrl = CreateAlbum(e.ID.ToString(), true);; } Uri postUri = new Uri(e.BackupAlbumUrl.Replace("entry", "feed")); stream.Position = 0; PicasaEntry entry = new PhotoEntry(); entry.MediaSource = new Google.GData.Client.MediaFileSource(stream, "backup", "image/jpeg"); PicasaEntry createdEntry = service.Insert(postUri, entry); }
private Album CreateAlbum(PicasaService session, PicasaFeed albumFeed, string targetAlbumName, AlbumAccessEnum albumAccess) { //create album (doesn't exist) WriteOutput(string.Concat("Creating Album: ", targetAlbumName), true); AlbumEntry newAlbumEntry = new AlbumEntry(); newAlbumEntry.Title.Text = targetAlbumName; newAlbumEntry.Summary.Text = targetAlbumName; newAlbumEntry.Published = DateTime.Now; Album newAlbum = new Album(); newAlbum.AtomEntry = newAlbumEntry; newAlbum.Access = albumAccess.ToString().ToLower(); Uri insertAlbumFeedUri = new Uri(PicasaQuery.CreatePicasaUri(this.PicasaUsername)); newAlbum.AtomEntry = (PicasaEntry)session.Insert(insertAlbumFeedUri, newAlbumEntry); m_albumCreateCount++; return(newAlbum); }
private string UploadPhoto() { try { PicasaService service = new PicasaService("picasaupload"); service.setUserCredentials(user.email, user.password); var file = "screenshot.png"; var fileStream = new FileStream(file, FileMode.Open); PicasaEntry entry = (PicasaEntry)service.Insert(new Uri("https://picasaweb.google.com/data/feed/api/user/default/albumid/default"), fileStream, "image/jpeg", file); fileStream.Close(); PhotoAccessor ac = new PhotoAccessor(entry); string albumId = ac.AlbumId; string photoId = ac.Id; string contentUrl = entry.Media.Content.Attributes["url"] as string; ThreadDelegate UploadFinish = delegate() { client.pid = photoId; client.uploading = false; label1.Opacity = 0; button1.IsEnabled = true; button1.Content = "Share"; return("succeed"); }; this.Dispatcher.BeginInvoke(DispatcherPriority.Send, UploadFinish); return("succeed"); } catch (Exception ex) { ThreadDelegate UploadFinish = delegate() { label1.Content = "Upload failed"; client.uploading = false; return("fail"); }; this.Dispatcher.BeginInvoke(DispatcherPriority.Send, UploadFinish); return("fail"); } }
public void DealWithRequest() { while (ol.IsListening) { //receive files via bluetooth try { ObexListenerContext olc = ol.GetContext(); ObexListenerRequest olr = olc.Request; string filename = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "\\" + DateTime.Now.ToString("dd-MM-yy HHmm") + " " + Uri.UnescapeDataString(olr.RawUrl.TrimStart(new char[] { '/' })); //remove newline filename = filename.Substring(0, filename.Length - 1); Console.Write("filetype: " + filename.Substring(filename.Length - 3, 3)); olr.WriteFile(filename); //add filename to fileList DoFileListUpdate(filename); if (filename.Substring(filename.Length - 3, 3).Equals("jpg") || filename.Substring(filename.Length - 3, 3).Equals("JPG") || filename.Substring(filename.Length - 3, 3).Equals("png") || filename.Substring(filename.Length - 3, 3).Equals("PNG") || filename.Substring(filename.Length - 3, 3).Equals("GIF") || filename.Substring(filename.Length - 3, 3).Equals("gif")) { //image upload to picasa Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(username, albumid)); System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename); System.IO.FileStream fileStream = fileInfo.OpenRead(); PicasaEntry entry = (PicasaEntry)picasaService.Insert(postUri, fileStream, "image/jpeg", filename); fileStream.Close(); //image properties entry.Title.Text = "Gogbot09: " + olr.RawUrl.TrimStart(new char[] { '/' }); entry.Summary.Text = "User content for GOGBOT 2009 festival, provided by bluetooth device: " + olr.UserHostAddress + " on: " + DateTime.Now.ToString("dd-MM-yy HHmm"); entry.Media.Keywords.Value = "gogbot, GOGBOT09, gogbot2009, bluetube"; //entry.Location = new GeoRssWhere(); //entry.Location.Latitude = 37; //entry.Location.Longitude = -122; PicasaEntry updatedEntry = (PicasaEntry)entry.Update(); Console.WriteLine("Photo: " + olr.RawUrl.TrimStart(new char[] { '/' }) + " uploaded."); } else { //upload video to youtube Video newVideo = new Video(); newVideo.Title = "Gogbot09: " + olr.RawUrl.TrimStart(new char[] { '/' }); newVideo.Tags.Add(new MediaCategory("People", YouTubeNameTable.CategorySchema)); newVideo.Keywords = "gogbot, GOGBOT09, gogbot2009, bluetube"; newVideo.Description = "User content for GOGBOT 2009 festival, provided by bluetooth device: " + olr.UserHostAddress + " on: " + DateTime.Now.ToString("dd-MM-yy HHmm"); newVideo.YouTubeEntry.Private = false; newVideo.Tags.Add(new MediaCategory("uploaded_through_bluetube", YouTubeNameTable.DeveloperTagSchema)); //newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122); // alternatively, you could just specify a descriptive string newVideo.YouTubeEntry.setYouTubeExtension("location", "Vrije Universiteit, Amsterdam"); newVideo.YouTubeEntry.MediaSource = new MediaFileSource(filename, "video/3gpp"); Video video = request.Upload(newVideo); //Check status if (video.IsDraft) { Console.WriteLine("Video is not live."); string stateName = video.Status.Name; if (stateName == "processing") { Console.WriteLine("Video is still being processed."); } else if (stateName == "rejected") { Console.Write("Video has been rejected because: "); Console.WriteLine(video.Status.Value); Console.Write("For help visit: "); Console.WriteLine(video.Status.Help); } else if (stateName == "failed") { Console.Write("Video failed uploading because:"); Console.WriteLine(video.Status.Value); Console.Write("For help visit: "); Console.WriteLine(video.Status.Help); } } } } catch (Exception e) { Console.WriteLine(e); } } }
private void buttonOk_Click(object sender, EventArgs e) { authenticate(); string userName = comboLogin.Text; string selectedAlbum = checkUploadToDropbox.Checked ? null : listAlbums.SelectedItem.ToString(); disableItemsForRun(); Thread thr = new Thread(new ThreadStart(delegate { FileInfo fileInfo = new FileInfo(fileName); FileStream fileStream = fileInfo.OpenRead(); PicasaEntry entry = null; try { if (checkUploadToDropbox.Checked) { entry = (PicasaEntry)service.Insert(new Uri(DROPBOX_URL), fileStream, "image/jpeg", fileName); } else { if (selectedAlbum != null) { Uri postUri = new Uri(PicasaQuery.CreatePicasaUri( userName, albumMap[selectedAlbum].Name)); entry = (PicasaEntry)service.Insert(postUri, fileStream, "image/jpeg", fileName); } } if (entry != null) { entry.Title.Text = name; entry.Summary.Text = textComment.Text; entry.Media.Keywords.Value = "Mazio"; } entry = (PicasaEntry)service.Update(entry); string contentUrl = entry.Media.Content.Attributes["url"] as string; Invoke(new MethodInvoker(delegate { uploadLog.Text = "Uploaded photo, URL is " + contentUrl + "\r\n"; })); } catch (GDataRequestException ex) { Invoke(new MethodInvoker(delegate { uploadLog.Text = "Upload failed: " + ex.Message + "\r\nResponse: " + ex.ResponseString + "\r\n"; })); } catch (IOException ex) { Invoke(new MethodInvoker(delegate { uploadLog.Text = "Upload failed: " + ex.Message + "\r\nResponse: " + ex.InnerException.Message + "\r\n"; })); } fileStream.Close(); Invoke(new MethodInvoker(delegate { done = true; updateItems(); buttonOk.Enabled = false; buttonCancel.Text = "Close"; })); })); thr.Start(); }