UploadCompleted

3 posts, 0 answers
  1. Aziz
    Aziz avatar
    32 posts
    Member since:
    Sep 2011

    Posted 27 Jun 2012 Link to this post

    I am curious how i would set the uploadHandler so once the last bit of the file is uploaded to the server the upload handler calls file.move(target,source) so that i can then move the file to my final location. The reason i need this is due to another service on my server, a filesystem watcher.

    Due to the nature of chunked uploading my filesystem watcher goes crazy if I upload directly to the final location. I thought i had this worked out but I don't think its writing the last chunk before moving the file as filesize is always smaller than the original.


    public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
        {
             
            string tempPath;
            tempPath = @"_tmp/_update";
            tempPath = System.Web.HttpContext.Current.Server.MapPath(tempPath);
            if (IsFinalFileRequest())
            {
                File.Move(tempPath, filePath);                                   
            }
            return base.SaveChunkData(tempPath, position, buffer, contentLength, out savedBytes);
        }
  2. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 29 Jun 2012 Link to this post

    Hi Jacob,

    The RadUpload control has a number of events at your disposal at different parts of the uploading cycle. This link will bring you to the list of events, and this link will bring you to the events cycle documentation.

    In your circumstance I would use the "UploadFinished" event, here is the official description:

    UploadFinished - occurs when all files have been processed and the upload finishes. The event handler receives two arguments:
    • The sender argument contains the RadUpload. This argument is of type object, but can be cast to the RadUpload type.
    • An RoutedEventArgs object.
    I hope this helps you achieve the results you're looking for.

    Good Luck,
    Lancelot
  3. DevCraft banner
  4. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 29 Jun 2012 Link to this post

    Hello Jacob,

    Looking at your code snippet I noticed that you've called the base.SaveChunkData() method after you've moved the file. However, please note that the base method has to be invoked first as it processes each chunk of the files. So in your case you'll first move the file and then process the last chunk which can cause the described issue. Instead, please try modifying your SaveChunkData implementation like this:
    public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
    {
        string tempPath;
        tempPath = @"_tmp/_update";
        tempPath = System.Web.HttpContext.Current.Server.MapPath(tempPath);
        bool result = base.SaveChunkData(tempPath, position, buffer, contentLength, out savedBytes);
        if (IsFinalFileRequest())
        {
            File.Move(tempPath, filePath);                                  
        }
        return result;
    }

    However, I'm not really sure what exactly is your scenario without looking at your RadUpload definition so I'm not sure if this change will work for you. If it doesn't you can try the approach Lance suggested or  send us more information on your scenario and the RadUpload definition - especially the TargetFolder settings of the control and where it saves the uploaded files before you move them.

    Greetings,
    Tina Stancheva
    the Telerik team

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

Back to Top