Uploading images to album

Dec 1, 2010 at 1:34 AM

I have a desktop C# app and I am trying to upload image using SmugMugModel with the code:

			ImageUpload upload = internalAlbum.CreateUploader();
upload.UploadStarted += new EventHandler<UploadEventArgs>(upload_UploadStarted);
upload.UploadProgress += new EventHandler<UploadEventArgs>(upload_UploadProgress);
upload.UploadCompleted += new EventHandler<UploadEventArgs>(upload_UploadCompleted);
foreach (string file in imagesToUpload.Keys)
{
try
{
upload.UploadImage(file);
}
catch (SmugMugException ex)
{
DisplayMessage.Error(ex);
}
}
I always get an error: "system error (invalid album id)"
I found that the image should be prepared in base-64 format and modified source ImageUpload class in UploadImage method to read all bytes from image file and convert them to base-64 bytes but it did not work either.
What do I do wrong?
Coordinator
Dec 1, 2010 at 7:28 PM

How do you create internalAlbum? It has to exist on the SmugMug site when you start uploading to it. When you create an album, they send back an album object with an id. Here are three ways to create an album:

1. var myCategory = user.CreateCategory(“myCategory”);

   var myAlbum = myCategory.CreateAlbum(“myAlbum”);

 

2. var myCategory = user.CreateCategory(“myCategory”);

    var mySubCategory = myCategory.CreateSubCategory(“mySubCategory”);

    var myAlbum = mySubCategory.CreateAlbum(“myAlbum”);

3. var myAlbum = user.CreateAlbum(“myAlbum”);

If the album already exists on the site, just get it using user.GetAlbums();

Then - I don’t know if you actually use the events. If you don't, just write it this way:

var myUpload = myAlbum.CreateUploader();

myUpload.UploadImage(filePath);

 

Put a break point and see when exactly you get the error. My guess is - when trying to create a new ImageUpload as this.id is null, this.id referring to the id of the current album object.

I'm glad that you are using the framework!

Maria

 
Dec 1, 2010 at 11:33 PM

Hi Maria!

Your framework is great. I’m a programmer with some experience and I may say its strait, easy to understand and follow, simple to use and well constructed.

Now, I am trying to upload an image to an existing album. I have a form for uploading images which receives an existing album object in its constructor (other form lets me chose the album from a list of albums retrieved from my site – it works great).

1. I retrieve albums:

User.GetAlbums(false, false, "id,Key", false, 0, string.Empty);

I add “id” and “Key” in extras to retrieve album id of each album.

2. I chose an album from a DataGridView control bounded to BindingSource (bsAlbums) with List<Album> as a DataSource, then I open the uploader dialog:

Album album = (Album)bsAlbums.Current;
UploaderForm f = new UploaderForm(album);
f.ShowDialog(this)

3. The internalAlbum is the album passed to the UploaderForm constructor.

4. I drag an image from Windows Explorer to the uploader dialog and perform an upload operation:

ImageUpload upload = internalAlbum.CreateUploader();
//upload.UploadStarted += new EventHandler<UploadEventArgs>(upload_UploadStarted);
//upload.UploadProgress += new EventHandler<UploadEventArgs>(upload_UploadProgress);
//upload.UploadCompleted += new EventHandler<UploadEventArgs>(upload_UploadCompleted);
foreach (string file in imagesToUpload.Keys)
{
try
{
upload.UploadImage(file);
}
catch (SmugMugException ex)
{
DisplayMessage.Error(ex);
}
}

I am using events to show the progress and upload of one than a single file – it’s for future and I may comment-out them for test, no problem. Anyway the progress works perfect and shows that the upload runs to the end of source file.

Ok, I switched off the events and tried again. Here are the results:

The exception is being thrown on the last line of the UploadImage method code because of the returned response from the SmugMug site:

{"stat":"fail","method":"smugmug.images.upload","code":5,"message":"system error (invalid album id)"}

According to wiki.smugmug.net code 5 is a system error, nothing more.

So, the image is uploaded, but not accepted by SmugMug…

I do not quite understand your suggestion about checking “this.id”. I have a breakpoint in the ImageUpload.UploadImage method where the exception is being thrown. I inspect “this” object and it does not contain “id” property. However the AlbumID property is set to some big int number and this is the value of the id propert of the internalAlbum object. I retrieved this property in point 1 of the procedure described above – I put the “id,Key” in the extras parameter to retrieve it (I don’t know if the Key is necessary, but who knowsJ).

One more thing – the implementation of the Highlight class is not complete: it does not implement the Type property which is returned in the JSon object when performing

internalAlbum.PopulateAlbumWithInfoFromSite();

(I was trying such things, thought it will help.) 
 
That’s all. Thank you for your response and sorry for the lengthy letter.
I am dying of waiting for some good news from youJ

Best regards

Grzegorz Dąbrowski

Poland

From: mariagh [mailto:notifications@codeplex.com]
Sent: Wednesday, December 01, 2010 8:29 PM
To: agd@rubikon.pl
Subject: Re: Uploading images to album [smugmugc3:236618]

From: mariagh

How do you create internalAlbum? It has to exist on the SmugMug site when you start uploading to it. When you create an album, they send back an album object with an id. Here are three ways to create an album:

1. var myCategory = user.CreateCategory(“myCategory”);

var myAlbum = myCategory.CreateAlbum(“myAlbum”);

2. var myCategory = user.CreateCategory(“myCategory”);

var mySubCategory = myCategory.CreateSubCategory(“mySubCategory”);

var myAlbum = mySubCategory.CreateAlbum(“myAlbum”);

3. var myAlbum = user.CreateAlbum(“myAlbum”);

If the album already exists on the site, just get it using user.GetAlbums();

Then - I don’t know if you actually use the events. If you don't, just write it this way:

var myUpload = myAlbum.CreateUploader();

myUpload.UploadImage(filePath);

Put a break point and see when exactly you get the error. My guess is - when trying to create a new ImageUpload as this.id is null, this.id referring to the id of the current album object.

I'm glad that you are using the framework!

Maria

Read the full discussion online.

To add a post to this discussion, reply to this email (smugmugc3@discussions.codeplex.com@discussions.codeplex.com)

To start a new discussion for this project, email smugmugc3@discussions.codeplex.com@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Coordinator
Dec 2, 2010 at 5:45 PM

Hi Grzegorz,

The problem is bigger than I initially anticipated.

SmugMug has just released a new version of their API and among the changes are the ones made to uploading pictures. I have to go through them and update the framework accordingly.

But there are issues with these updates on their side as well - for eg, albums.get only returns public albums now. I’ve emailed them and I’m waiting for a reply/fix.

From the things you listed in your email – you shouldn’t need to add “id” and “Key” in extras to retrieve album id of each album, these are supposed to be returned by the API in the album object they return (no matter if heavy response or not). I haven’t had time to look into the Highligh class yet, but I will once I start updating the framework, probably during the weekend. For now, I’m waiting for SmugMug to fix their issues.

Thanks for the praises :)

Maria

Dec 2, 2010 at 9:11 PM

Now everything is clear. I am using Send to SmugMug plug-in to Windows Explorer and I noticed a problem in its work. Now it cannot send images to existing albums. It is able to upload images to a new album only.

I thought you will find a solution for my problem but we have to wait for SmugMug.

Thanks very much.

Grzegorz (Greg in english)

Coordinator
Dec 7, 2010 at 10:06 PM

I’ve realized what the problem is - As part of overall site hardening against side jacking, a new cookie _su is returned when logging in. This cookie is required to be present when making subsequent calls over https.

I’m in the process of making the changes. Unfortunately this is going to be a version breaking change.

The upload function has also been changed and it requires the image to be sent in base64 format (you had mentioned that before as well). It can also receive new parameter – hide is one of them.

There are also a couple of new features, new objects to be added and changes to the Album and Image objects.

I will work on the cookie first and upload that until the end of the week and then on the other updates. I hope to be done with them by the holydays, but it all depends on the time I have available.

 

Maria

Dec 8, 2010 at 9:57 PM

I suspected two things: either the SmugMugModel is not working or the API has changed (or has been greatly improved) :) Now it's clear - your investigation has proved it: we have a breaking change.

Seriously, it’s a good idea to prevent the side from jacking and make it more safe – it holds our work and memories.

Ok. I am patient and waiting for the results of your efforts. I am sure many others are silently rubbing their hands with glee over the new framework.

I have one question: what is the purpose of the API Key I have generated on then SmugMug page? The SmugMug framework (your SmugMugModel) does not need it.

Coordinator
Dec 8, 2010 at 10:08 PM

I’ve done the changes so that the _su cookie is send with each object, but now some of the functions that didn’t work before, now work perfectly and some don’t work at all. I’m waiting on SmugMug to tell me if it’s a problem on their end, if they had anybody else with this issue.

The API key is to put in your own app, so that SmugMug knows what app is hitting the site, etc.

 Maria

Dec 8, 2010 at 10:24 PM

So we have to just wait.

I know what the API Key is for but I don't know how to present it in my app for SmugMug to know it. I have not done such a thing and my app is connecting with the site, listing albums and so on. I'd been searching for some info where to put my API Key but i didn't find anything.

Greg

Coordinator
Dec 9, 2010 at 5:42 PM

When you do stuff using the framework, it sends the requests for you to SmugMug and within those requests; I’ve embedded my own API key (I send it with each request, along with the Session Id, the method you are calling, the parameters, etc.). I don’t think you can send your own API key because you already send one.

Maria

Dec 9, 2010 at 11:49 PM

Right, I've found it in CommunicationHelper. But maybe you should let (or even require) the end programmer to enter its own API Key. I don't know what SmugMug thinks about it. Anyway now it's clear to me.

Greg

Coordinator
Dec 12, 2010 at 10:12 AM

Everything should work fine right now, it does for me. Even the upload.

I haven't really solved the _su issue, I'm sending everything through http for the moment, so that we have a workable framework. I've also done some updates, more to follow :)

Maria

Dec 12, 2010 at 12:30 PM

Maria, you rock! Uploading is working very well. Now I can move on and implement deleting and other administering stuff. Waiting for other improvements and changes.

Thanks!

Greg