Multiple Thumbnail Generators

May 5, 2011 at 9:18 AM
Edited May 5, 2011 at 10:15 AM

So we discovered this ability to be able to use more than one thumbnail generator at a time  (ThumbGeneratorAdapter).

The reason we needed this feature was because we are using the fileuploader on a custom made blog. Our filing system for this was to be based on using prefix's with an autogenerated date.
But we want to have a thumbnail and a large image, both with a prefix for the described reason. We discovered that only thumbnails could be given a prefix. So we had the idea to use thumbnails for
every image created and give the original an empty location, thus not saving it.

Here came the problem however. The thumbnail generator adapter can only be used once per uploader object by default, and we couldnt give it an ID to allow more than one. Needless to say we were stuck.

Our solution came using an array for the adapters, and instead of using the properties in the designer, we called them in the code behind. With this we were able to set two 'ThumbGeneratorAdapter''s
to work seperatly and give out more thumbs, in other words we can have as many thumbnails generated as we want, and here is how:

Our front code:


       <fjx:FileUploader ID="FileUploader1" runat="server">
                <fjx:FileSaverAdapter Runat="server" />
                <fjx:ThumbGeneratorAdapter Runat="server" 
                 Extensions="jpg;jpeg" MaximumWidth="500" MaximumHeight="500"  />
                <fjx:ThumbGeneratorAdapter Runat="server" 
                 Extensions="jpg;jpeg" MaximumWidth="200" MaximumHeight="200"  />

Here is the code behind:


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using com.flajaxian;

namespace MultiUploadTest
    public partial class _Default : System.Web.UI.Page

        protected void Page_Load(object sender, EventArgs e)
            //Saying adapter 0 (array) is a 'filesaveradapter'
            ((com.flajaxian.FileSaverAdapter)FileUploader1.Adapters[0]).FolderName = "";
            ((com.flajaxian.ThumbGeneratorAdapter)FileUploader1.Adapters[1]).FolderName = "bin"; //Can be set to go anywhere
            ((com.flajaxian.ThumbGeneratorAdapter)FileUploader1.Adapters[1]).Prefix = "test123_";
            ((com.flajaxian.ThumbGeneratorAdapter)FileUploader1.Adapters[2]).FolderName = "bin";
            ((com.flajaxian.ThumbGeneratorAdapter)FileUploader1.Adapters[2]).Prefix = "test789_"; //Setting '.Adapters[2]' refers to the second thumnail adapter in the design code.

Anyone who has analyzed this in great detail may ask, "why they are putting the images in the bin folder." Well there is no reason :P, we just used that temporarily,
you can use wherever you want.

In more detail, on 'Page_Load' we have setup an array that is linked to the 'ID' of 'fileuploader1'. From there we the object, such as 'filesaveadapter'
from within the brackets and then the property on the end. So '.foldername' will place this object's files in the given location.
Furthermore, although the array is seperatated, it is really one large array, that is why the number in the '[]' is the same for some. We are just stating properties
on multiple lines. I am sure that you can abbreviate this so to speak and shorten it without calling the entire array over and over :P.
But this works for us and we are happy with it.

So I hope this helps, goodluck and have fun :D.