Browse ImageVault with PicLens

PicLens is a very useful addon for your browser that lets you browse images and other media in a 3D view. I have created a simple example on how you can enable PicLens on your EPiServer site running ImageVault.

The following walkthrough shows you how to enable PicLens on any website using ImageVault.This tutorial shows the basics of creating a Media RSS and it will expose all images from ImageVault. In part 2 of this article you will be able to download a template with a little more functionality. If you don´t have PicLens installed in your browser please visit http://www.cooliris.com/ to install.

To create the media RSS you need to create a generic handler. The media RSS is a standard for syndicating multimedia files (audio, video, image) in RSS feeds. So lets create a new generic handler and add the methods and properties we need.

public class PicLensHandler : IHttpHandler {
    public void ProcessRequest(HttpContext context) { }
    private void WriteEntry(XmlTextWriter xtw, IVFileData item) { }
    public bool IsReusable {
        get { return true; }
    }
}

Now its time to enable processing of the HTTP web request by overriding the ProcessRequest method. This is where we create the basic media rss structure needed for PicLens to work.

public class PicLensHandler : IHttpHandler {
    public void ProcessRequest(HttpContext context) {
    int id = Convert.ToInt32(context.Request["album"]);
    context.Response.ContentType = "text/xml";
    XmlTextWriter xtw = new XmlTextWriter(context.Response.Output);
    xtw.Formatting = Formatting.Indented;
    xtw.WriteStartDocument();
    xtw.WriteStartElement("rss");
    xtw.WriteAttributeString("version", "2");
    xtw.WriteAttributeString("xmlns", "media", null, "http://search.yahoo.com/mrss");
    xtw.WriteStartElement("channel");
    foreach (IVFileData fileData in IVDataFactory.GetFiles(IVDataFactory.RootAlbumId,true)) {
        WriteEntry(xtw,fileData);
    }
    xtw.WriteEndElement();
    xtw.WriteEndElement();
    xtw.WriteEndDocument();
}
private void WriteEntry(XmlTextWriter xtw, IVFileData item) { }
public bool IsReusable {
    get { return true; }
}

To complete the media rss we need to provide some code to our WriteEntry method. This method creates an item entry with three different ImageVault handler links to different image sizes (weburl, thumbnailurl and largeurl).

public class PicLensHandler : IHttpHandler {
    public void ProcessRequest(HttpContext context) {
        int id = Convert.ToInt32(context.Request["album"]);
        context.Response.ContentType = "text/xml";
        XmlTextWriter xtw = new XmlTextWriter(context.Response.Output);
        xtw.Formatting = Formatting.Indented;
        xtw.WriteStartDocument();
        xtw.WriteStartElement("rss");
        xtw.WriteAttributeString("version", "2");
        xtw.WriteAttributeString("xmlns", "media", null, "http://search.yahoo.com/mrss");
        xtw.WriteStartElement("channel");
        foreach (IVFileData fileData in IVDataFactory.GetFiles(IVDataFactory.RootAlbumId,true)) {
            WriteEntry(xtw,fileData);
        }
        xtw.WriteEndElement();
        xtw.WriteEndElement();
    xtw.WriteEndDocument();
}
private void WriteEntry(XmlTextWriter xtw, IVFileData item) {
    xtw.WriteStartElement("item");
    xtw.WriteElementString("title", item.Title);
    xtw.WriteElementString("link", new IVUrlBuilder { Id = item.Id, Width = 500, Height = 500 }.ToString();
    xtw.WriteStartElement("media:thumbnail");
    xtw.WriteAttributeString("url", new IVUrlBuilder { Id = item.Id, Width = 300, Height = 300 }.ToString();
    xtw.WriteEndElement();
    xtw.WriteStartElement("media:content");
    xtw.WriteAttributeString("url", new IVUrlBuilder { Id = item.Id, Width = 1024, Height = 1024 }.ToString();
    xtw.WriteEndElement();
    xtw.WriteEndElement();
}
public bool IsReusable {
    get { return true; }
}

Now your done and we can add the handler to your head section in your x/html document like this:

<link rel="alternate" type="application/rss+xml" title="Kloojed - ImageVault image stream" href="/PicLensHandler.ashx" />

Visit your page and enjoy your ImageVault images in PicLens. Hope you enjoyed this article and feel free to drop a comment below.

  1. there seems to be an error regarding the usage of IVFileData. Any assembly reference need to be declared to use the function?

    btw, can i insert database(sql server) into this? coz I would like to call out image from the server

    thanks

    • Posted by weyyau
  2. weyyau

    there seems to be an error regarding the usage of IVFileData. Any assembly reference need to be declared to use the function?

    You need to have ImageStoreNET and ImageVault.EPiServer5 as references in your project.

    btw, can i insert database(sql server) into this? coz I would like to call out image from the server

    Well you could to that but I would recommend you to use the API when working with images in ImageVault.

  3. I have inserted an EPiServer Page Template and then added at the top of the page: using ImageStoreNet; using ImageVault.EPiServer5; But then these namespace values are not found. Am I missing an directive?

    Thanks!

    • Posted by Mirjam
  4. Mirjam

    Am I missing an directive?

    Did You add ImageStoreNET.dll and ImageVault.EPiServer5.dll as a reference in your project?

  5. Adding the references worked!

    Now I can't find any albums or files in IVFileData. I do get an RootAlbumID, but everything else seems empty. When I try to get a file I get an access denied message: IVFileData pic = IVDataFactory.GetFile(10); Is that the reason why the file collection is empty?

    Thanx!

    • Posted by Mirjam
  6. Mirjam

    If you want to show all files from ImageVault you could use the overload for GetFiles which takes a third argument. So your code should look something like this:

    IVDataFactory.GetFiles(IVDataFactory.RootAlbumId, true, IVAccessLevel.IgnoreAccess)

    or you could set the access rights on the album so everyone has access to your files. For more information about the api check out the sdk on Meridium.se.

Leave a comment

Use markdown syntax to add formating to your comment.

Enter XOF, but type the third character three times.