Custom Server-Side Handler

10 posts, 0 answers
  1. Tony
    Tony avatar
    6 posts
    Member since:
    Aug 2008

    Posted 03 Jan 2009 Link to this post

    Hi,

    Do you have a sample working custom server-side handler that demostrates more about the ProcessStream()?

        public override void ProcessStream()  
        {  
            base.ProcessStream();  
            if (this.IsFinalFileRequest())  
            {  
                // Insert here your custom logic for processing the file stream.  
                // You can read the saved file on the disc and to process it in the way you need.  
                // You can save the file in DB, compress it, etc.  
                // you can access the form parameters by using the RadUploadConstants  
                string targetFolder = this.Request.Form[RadUploadConstants.ParamNameTargetFolder];  
                // Or by using the predefined properties/methods in the base handler  
                string targetFolder2 = this.TargetFolder;  
                string targetPhysicalFolder = this.TargetPhysicalFolder;  
                bool isFinalRequest = this.IsFinalFileRequest();  
                // to send back a parameter - for example the error message, or the result from the upload operation  
                // use the AddReturn  
                this.AddReturnParam(RadUploadConstants.ParamNameSuccess, false);  
                this.AddReturnParam(RadUploadConstants.ParamNameMessage, "Unable to open the Database");  
            }  
        }  
      
     
    Thanks.
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 05 Jan 2009 Link to this post

    Hi Tony,

    We don't have an example application with a custom server side handler. What is the scenario that you are into?

    Regards,
    Valentin.Stoychev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. Tony
    Tony avatar
    6 posts
    Member since:
    Aug 2008

    Posted 05 Jan 2009 Link to this post

    Hi Valentin:

    Here are the requirements for my upload process:

    After one file upload starting or uploaded, I need to:
    - Rename the file and save it to a specific folder
    - Generate a thumbnail from the file and save it to the database
    - Retreive the file information and save it to the database

    Do I do these tasks inside the ProcessStream()?

    Thanks

    Tony
  5. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 05 Jan 2009 Link to this post

    Hi Tony,

    Yes, this is the place to perform these tasks. If you place your logic inside the IF statement it should be ok.
    public override void ProcessStream()
    {
    base.ProcessStream();
    if (this.IsFinalFileRequest())
    {
    // place your code here
    }
    }

    Please let us know how it goes.

    Greetings,
    Valentin.Stoychev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Tony
    Tony avatar
    6 posts
    Member since:
    Aug 2008

    Posted 06 Jan 2009 Link to this post

    Hi Valentin:

    Thanks for the info, that should work for now.

    Also, can we access HttpContext from the handler? Or anyway we pass some data to it? I need to pass a different target folder path for different uploads.

    Thanks

    Tony
  7. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 06 Jan 2009 Link to this post

    Hi Tony,

    Check this help article:
    http://www.telerik.com/help/silverlight/passing_custom_params_to_the_server_side_handler.html

    Best wishes,
    Valentin.Stoychev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Geovani
    Geovani avatar
    3 posts
    Member since:
    Dec 2010

    Posted 04 Jan 2011 Link to this post

    Hello,

     I’ve tried to use your code, but it isn’t working when I upload more than 1 file because this method is returning true just when the last file is updated.

    So I’ve implemented this code and now it is working ok, because I’m calling the method IsFinalFileRequest before call the ProcessStream method. What could I do to throw an exception and show it in the upload component?

    bool finalFileRequest = this.IsFinalFileRequest();

    base.ProcessStream();

    if (finalFileRequest)

    {

    try

    {

        // My code.

    }

    catch

    {

        // How could I throw the exception here and show it in the component.

    }

    }

    Thanks

  9. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 07 Jan 2011 Link to this post

    Hi Geovani,

    A few months ago the RadUpload control was modified to introduce new functionality. However, a few changes were introduced. Please have a look at this article to learn more info.

    Also, you may find useful the following articles as well:
    You can also find an example of how to upload images in a database here.

    I hope this information will help you implement your scenario. Still, if you need more info please let us know.

    All the best,
    Tina Stancheva
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  10. MD
    MD avatar
    55 posts
    Member since:
    Jul 2012

    Posted 19 Oct 2011 Link to this post

    Why is it that IsFinalFileRequest() returns true in ProcessStream only when it is the last chunk of the last file when there are multiple files uploaded and IsFinalFileRequest() is called after the base call?  It returns true before you call the base.ProcessStream() when it is the last chunk of a file regards of the file's position when there are multiple ones, but it returns false when called after base.ProcessStream() when the file is not the last one even though it is the last chunk of that file.
  11. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 24 Oct 2011 Link to this post

    Hello MD,

    The main logic processing the stream of the selected files is in the ProcessStream() method. It is called as soon as the handler receives a file for upload and then it interacts and triggers most of the methods of the RadUploadHandler. This is why if you want to customize the behavior of the UploadHandler, it is safer to override the SaveChunkData() method which is called as soon as a chunk of file is processed. If you want to implement custom logic as soon as the last chunk of a file is processed - it is best to place this logic in the SaveChunkData() method.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner