Custom Adapter Example

Sep 12, 2008 at 5:06 AM
Hi,

  I downloaded the help file but for some reason, I can not view the .chm file. 

  Anyway, my goal is to actually create a custom adapter so that I can process the file and upload it to my Smugmug account.  I like the way it allows a user to select multiple files and when the user clicks on upload, I'd like to get the list of filenames, and process them.

 Any help is always appreciated.

Thanks!
wuttrain
Coordinator
Sep 12, 2008 at 7:16 AM

Are you using Windows? I have no problems seeing the .chm file on Vista or XP.

Adding custom adapter is easy. Here is the description that I copy and paste from docs:

Server side adapters

Server side adapters are designed to extend the functionality of the Flajaxian FileUploader web control. The control comes with two adapters:

  1. FileSaverAdapter - used for saving the files in a folder on the server.

    Here is an example of how you can use it:

    <fjx:FileUploader ID="FileUploader1" runat="server" >
        <Adapters>
            <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" />
        </Adapters>
    </fjx:FileUploader>
    

    In this example file will be uploaded on the folder UploadFolder

  2. ThumbGeneratorAdapter - used to generate thumbnails for the image files.

    Here is an example of how you can use it:

    <fjx:FileUploader ID="FileUploader1" runat="server" >
        <Adapters>
            <fjx:ThumbGeneratorAdapter Runat="server" 
                Extensions="jpg;jpeg" FolderName="UploadFolder" 
                Suffix="_thumb" MaximumWidth="200" MaximumHeight="200" />
        </Adapters>
    </fjx:FileUploader>
    

    In this example the templates will be generated in a folder UploadFolder with suffix _thumb for the files with extension jpeg or jpg. The thumbnails will be withing the frame of 200 pixels height and width.


    You can use more than one adapter. They will be executed in the order of their definition. For example:

    <fjx:FileUploader ID="FileUploader1" runat="server" >
        <Adapters>
            <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" />    
            <fjx:ThumbGeneratorAdapter Runat="server" 
                Extensions="jpg;jpeg" FolderName="UploadFolder" 
                Suffix="_thumb" MaximumWidth="200" MaximumHeight="200" />
        </Adapters>
    </fjx:FileUploader>
    

Custom Adapters

 

You can create your own adapter. They must extend com.flajaxian.FileUploaderAdapter. This is a simple tamplate you can use to create your own server side adapter:

using System;
using System.Web;
using System.Collections;
using com.flajaxian;

namespace CustomNamespace { public class CustomAdapter : FileUploaderAdapter { /// <param name="file">Incoming file</param> /// <param name="state"> /// Hashtable that can be used to transfer a state between different adapters. /// This file is not used for this adapter. /// </param> public override void ProcessFile(HttpPostedFile file, Hashtable state) { // process the file here } } }

Then register is as

<%@ Register TagPrefix="custom" Namespace="CustomNamespace" Assembly="your.assembly" %>

note that your.assembly is without .DLL

then 

<fjx:FileUploader ID="FileUploader1" runat="server" >
    <Adapters>
        <custom:CustomAdapter Property1="ABC" />
    </Adapters>
</fjx:FileUploader>

Sep 12, 2008 at 4:32 PM

Hi flajaxian,

  Thank you for your reply.

  I created my own custom adapter and added a breakpoint to the ProcessFile method in my adapter.  I ran the app but it seems that after I selected the files and clicked the upload button,  the ProcessFile method is not called.  Are there properties that I need to set to make this happen?  I'm sure I missed something.

Additionally, when I look at the Flajaxian control in the design mode, I see the following error messages: "Error Rendering Control - FileUploader1 An unhandled exception has occurred.  Request is not available in this context."


Anyway, here is my code to make it more understable:

Thanks!
wuttrain

CustomFlajSmug.vb

 

Imports

 

System
Imports System.Web
Imports System.Collections
Imports System.IO
Imports com.flajaxian

 

 

Namespace CustomFlajSmugNamespace

 

 

Public Class CustomFlajSmug : Inherits FileUploaderAdapter

 

 

Public CName As String

 

 

Public Overrides Sub ProcessFile(ByVal file As System.Web.HttpPostedFile, ByVal state As System.Collections.Hashtable)

 

 

  ' code here

End
Sub

 

 

 

 End Class

 

End

 

Namespace


in my web page:

 

<%

@ Register TagPrefix="fjx" Namespace="com.flajaxian" Assembly="com.flajaxian.FileUploader" %>
<%
@ Register TagPrefix="custom" Namespace="FlajSmug.CustomFlajSmugNamespace" Assembly="FlajSmug" %>

 

inside body:


<fjx:FileUploader ID="FileUploader1" runat="server" >
  <Adapters>
    <custom:CustomFlajSmug CName="smug" />
  </Adapters>
</fjx:FileUploader>

 

 

 




 

Coordinator
Sep 12, 2008 at 6:18 PM
Hi wuttrain

I see that the namespace  Namespace="FlajSmug.CustomFlajSmugNamespace"

does not match with class namespace Namespace CustomFlajSmugNamespace

may be also you are not in debug mode

I set up an example for you that works fine:

http://www.flajaxian.com/flajaxian.com/FlajSmug.zip
Coordinator
Sep 12, 2008 at 6:23 PM
And about the design mode it hasn't been integrated, but I don't see why would you need to use the design mode.

We may integrate it in the future but now I see no value of spending time for that.
Sep 13, 2008 at 3:43 AM
Hi flajaxian,

  Thank you for your response.  I removed FlajSmug from the Namespace="FlajSmug.CustomFlajSmugNamespace" and it gave me this error when I try to build it:

      Unknown server tag 'custom:CustomFlajSmug'

Do you have any idea why?  Your example works though.  Maybe I'm doing something different for VB.net.  I guess I will have to use C# for this adapter.

Thanks,
wuttrain
Sep 13, 2008 at 6:25 AM
Hi flajaxian,

  I decided to use C# just for the custom adapter just to make it work for now. I really couldn't make it work with VB.Net. 

  I have another question (I created a new discussion item), it's about getting the path for the file I want to upload.  How do I get it?

Thanks again.
wuttrain
Coordinator
Sep 13, 2008 at 7:50 AM
Sorry I am affraid I won't have time to learn VB for this problem but may be some other participant of the forum will be kind enough to translate this in VB? http://www.flajaxian.com/flajaxian.com/FlajSmug.zip