Sunday, May 27, 2012

SSIS: How to Load images into Picasa web album?

Picasa is an online repository for storing, editing and sharing images. There are many methods available to upload or download images from Picasa web album. In this post we will learn how we can load images from our local folder to Picasa web album through SSIS.

The very first thing we need to do is to follow the prerequisite we need to start with Picasa web services. We need a Google account to start with. We also need to download and install Google Data API library. Google Data API library is available in different platform (PHP, Python, .NET, Java, Javascript etc). Since SSIS supports .NET so all we need to do is to go to http://code.google.com/p/google-gdata/downloads/list and download Google Data API setup.

Once you have downloaded and installed the API setup the next thing we need to do is the drop the DLLS to GAC. For this we need to run Visual Studio Command Prompt as an Administrator and add following DLLS to Global cache.

Google.GData.Photos.DLL
Google.GData.Client.DLL
Google.GData.Extensions.DLL

After doing the setup and dropping of DLL the next thing, I did was to log into Picasa web account and created an album SSIS-Image-Test

The next thing, I did was to get AlbumID of the newly created web Album. For this I clicked on the RSS link of the web album.

Clicking on RSS will show the XML Feed and we can read the AlbumID from the XML Feed.

I have following images in my local folder which we will upload to Picasa web album (SSIS-Image-Test).

So we are all set to start with our package. In SSIS at control flow, I have two components: a ForEach loop container and a Script Task.

I am using the Foreach File Enumerator and Folder configuration is pointed to my local folder.

I am using following variable to store each of the file item location from Foreach file numerator

In the Script Task component, I have added reference of Google Data API DLLs. Script Task will run for each of the file stored in the local folder. I am importing following namespace in the Script Task code.

using Google.GData.Photos;
using Google.GData.Extensions;
using Google.GData.Extensions.Location;
using Google.Picasa;
using System.IO;

The .NET Conde snippt in Script Task is following:

public void Main()
  {
  //Create new Picasa Service
  PicasaService myPicasa = new PicasaService("Vikash-Test-Picasa");
  myPicasa.setUserCredentials("abc@gmail.com", "abcpassword");

//Create new URI by passing userid and AlbumID
  Uri newURI = new Uri(PicasaQuery.CreatePicasaUri("abc", "5746268939336053009"));

//Upload all images to Picasa
 
  System.IO.FileInfo newFile = new System.IO.FileInfo(Dts.Variables["ImageFile"].Value.ToString());
  System.IO.FileStream neFStream = newFile.OpenRead();
  PicasaEntry newEntry = (PicasaEntry)myPicasa.Insert(newURI, neFStream, "Image/jpeg", "Test");
  neFStream.Close();
  Dts.TaskResult = (int)ScriptResults.Success;
  }

After setting up the Script Task code I connected with the internet and run the SSIS package.

The SSIS package execution result shows that it run successfully. I log into my Picasa web account and navigated to the album SSIS-Image-Test. The image files were loaded successfully.

So our objective to load images into Picasa web album is achived.

Thanks for reading this post.

If you wan to explore more on Picasa with .NET; please visit Google API Series in .NET

Related Article:

Popular Posts

Real Time Web Analytics