Multiple Photo upload to flickr!

Topics: Developer Forum, Project Management Forum, User Forum
Jun 8, 2012 at 9:52 PM
Edited Jun 8, 2012 at 9:53 PM

H all,

I am successful in uploading a single picture to my photostream of flcikr using flickr.NET API. Now I wanted to upload multiple pictures (more than one photos) once. I write the following code. When I run it, it of course uploads the pictures but the windows form i use to upload crushes. Then it needs me to debug it and yet I have got nothing so far. Here is my code used for uploading. 

 

// Uploading photos to flickr           

for (int n = 0; n < fileName.Count; n++ )           

{

 try               

{                   

Photo ph = new Photo();                   

Thread threadUpload = new Thread(delegate()                       

{                           

ph.PhotoId = flickr.UploadPicture(fileName.ElementAt(n), Title, Desc, Tags, true, true, true);                           

flickr.PhotosCommentsAddComment(ph.PhotoId, phComm);                                                     

phID.Add(ph.PhotoId);     // Add photoIDs to a string list for letter use                      

webURL.Add(ph.WebUrl);     //  Add webURL to a string for letter use

});                   

threadUpload.Start();               

}               

catch (FlickrException Ex)               

{                   

Console.Beep();                   

MessageBox.Show(Ex.Message + "!", "Error!");                   

return;               

}           

}

I keep the records of both photoID and URL for later use. filename is a string list that has the photo file path and name details. I take one file for each iteration using "n" as an index to access the strings. So what shall I do to upload more than one photos with out crushing my windows form application. Thanks!!


Coordinator
Jun 9, 2012 at 9:43 AM

Firstly, you say you are getting an error, but don't say what the error is.

Secondly, your try/catch statement is outside of the Thread function, so won't catch errors inside the thread delegate. Try putting a try catch inside that part of the code.

Also, the web url property will not be a valid URL, as the Photo.UserId property won't have been set. The Photo class is only really designed to be used by the FlickrNet library and you shouldn't really be creating them yourself.

Sam

Jun 9, 2012 at 3:54 PM

Hi sam,

i rearrange the code as you suggested above. It catches some errors and returns them. That is really helpful. But still the problem persists. My application programs crashes and a small window appears. This window wants me to debug the application.  It says "vshost32-clr2.exe" has stopped working. I saw everything and there is no error inside the code. here is the updated code in case you need it. I truncated some part to focus on the upload code section. 

// uploading a picture           

Flickr flickr = new Flickr(apiKey, sharedSecret, authToken.Token);           

Photo ph = new Photo();           

ph.UserId = authToken.User.UserId;

 // Uploading photos to flickr           

Thread Upload = new Thread(delegate()           

{                              

try               

{                   

for (int n = 0; n < imfileName.Count; n++ )                   

{                       

// Getting photo details                       

string phFileName = imfileName.ElementAt(n);  // Reads files from a folder                      

string phTitle = title.ElementAt(n);    // title for each photo                    

string phTags = tags.ElementAt(n);    // tag for each photo                    

string phDesc = description.ElementAt(n);    // description for each photo                    

string phComm = comment.ElementAt(n);       // comment for each photo                             

ph.PhotoId = flickr.UploadPicture(phFileName, phTitle, phDesc, phTags, pub, fam, fri);   // pub, fam and fri are privacy (user choice not shown here)                

if (phComm != "")   // checking for empty comment to avoid "empty comment error!"                     

{                           

flickr.PhotosCommentsAddComment(ph.PhotoId, phComm);         // if there is, add comment to the photo                                          

}                                               

phID.Add(ph.PhotoId);                       

webURL.Add(ph.WebUrl);                                                                                                          

// Creating photoset and add photos to the photo set                       

if (n == 0)                       

{                           

if (photosetRichTextBox.Text == "")              // checking photoset title             

{                               

flickr.PhotosetsCreate(phSetTitle, ph.PhotoId);             // creating photoset using the first photo ID              

}                           

else                           

{                               

flickr.PhotosetsCreate(phSetTitle, phSetDescription, ph.PhotoId);       // adding photos to the photoset created above (there is error here)                   

}                       

}  

}

}                                       

catch (FlickrException Ex)               

{                   

// Handling upload error exception!                   

Console.Beep();                   

MessageBox.Show(Ex.Message + "!", "Error!");                   

return;               

}         

});           

Upload.Start();

 

So As you can see, the error is i think related to my PC. but now let me ask you one thing. When i add photos to the photoset, it says "photo set ID error" but i give it the ID of the first photo as you can see from the above? What is the problem? thanks in advance!!

Jun 9, 2012 at 6:40 PM
Edited Jun 9, 2012 at 6:54 PM

Hi all,

The problem is solved. I get the photoset ID from "photoset collection" class and then the upload works fine. The other debug error is also handled. It was due to "Cross thread operation". I tried to call the UI staffs like "textbox" inside the thread delegate () class which is wrong. Thanks for your followup sam. Still I have one last question. I tried to include a progress bar to show the upload progress for the user (as indicated on this site: http://ctlabs.blogspot.it/2009/03/upload-photos-using-flickr-api-in-net.html ) but it doesn't work and i couldn't figure out any problem. Can someone show me how to do it. Thanks !!

Coordinator
Jun 13, 2012 at 9:05 AM

Yeah, unfortunately at the moment I don't think the upload progress event is being fired. Its a bug I've been meaning to fix for a while.

Sam