This is a migrated thread and some comments may be shown as answers.

OnFileUploaded not firing

2 Answers 170 Views
CloudUpload
This is a migrated thread and some comments may be shown as answers.
Vance Smith
Top achievements
Rank 1
Vance Smith asked on 30 Oct 2013, 06:20 AM
Hi,

The OnFileUploaded event is not firing. Am i missing something?

aspx

<telerik:RadCloudUpload 
                        ID="CU" 
                        runat="server" 
                        MultipleFileSelection="Disabled" 
                        ProviderType="Azure" 
                        MaxFileSize="2147483648"
                        OnFileUploaded="CU_FileUploaded"
                        OnClientUploadFailed="OnClientUploadFailed" 
                        AllowedFileExtensions=".pdf"
                        httpHandlerUrl="~/AzureUploadHandler.ashx">
                    </telerik:RadCloudUpload>

aspx.cs

 protected async void AU_FileUploaded( object sender, Telerik.Web.UI.FileUploadedEventArgs e ) {
            DateTime startDate = DateTime.Now;
            Bll.BfxFiles.SaveFileAsync( Sys.Config.DomainId, 0, 1, e.File.InputStream, e.File.FileName );

            AsyncUploadLabel.ForeColor = System.Drawing.Color.Green;
            AsyncUploadLabel.Text = string.Format( "File '{0}' uploaded successfully to Azure BLOB storage.<br/>Start: {1}<br/>End: {2}<br/>Size: {3}", 
                e.File.FileName, startDate.ToString(), DateTime.Now.ToString(), e.File.ContentLength.ToString() );
        }

handler

<%@ WebHandler Language="C#" Class="AzureUploadHandler" %>

using System;
using System.Web;

public class AzureUploadHandler : Telerik.Web.UI.CloudUploadHandler, System.Web.SessionState.IReadOnlySessionState {
    
    public override void SetKeyName(object sender, Telerik.Web.UI.CloudUpload.SetKeyNameEventArgs e) {
        if ( HttpContext.Current.Session["SelectedBfxFileId"] == null ) {
            HttpContext.Current.Response.Redirect( "~/Login.aspx?m=1" ); // session timed out
        }
        else {
            try {
                int bfxFileId = Convert.ToInt32(  HttpContext.Current.Session["SelectedBfxFileId"] );
                if ( bfxFileId == 0 ) {
                    HttpContext.Current.Response.Redirect( "~/Error.aspx?e=1" ); // invalid bfxFileId
                }
                else {
                    e.KeyName = Bll.BfxFiles.BuildBlobName( bfxFileId, e.OriginalFileName );
                }
            }
            catch ( Exception ex ) {
                throw ex;
            }
        }
    }
}

2 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 01 Nov 2013, 03:59 PM
Hi Vance,

This event will be fired after you cause a postback. Also I have noticed that there is a typo in your markup:
<telerik:RadCloudUpload
                        ID="CU"
                        runat="server"
                        MultipleFileSelection="Disabled"
                        ProviderType="Azure"
                        MaxFileSize="2147483648"
                        OnFileUploaded="CU_FileUploaded"
                        OnClientUploadFailed="OnClientUploadFailed"
                        AllowedFileExtensions=".pdf"
                        httpHandlerUrl="~/AzureUploadHandler.ashx">
                    </telerik:RadCloudUpload>

protected async void AU_FileUploaded( object sender, Telerik.Web.UI.FileUploadedEventArgs e ) {
           DateTime startDate = DateTime.Now;
           Bll.BfxFiles.SaveFileAsync( Sys.Config.DomainId, 0, 1, e.File.InputStream, e.File.FileName );
 
           AsyncUploadLabel.ForeColor = System.Drawing.Color.Green;
           AsyncUploadLabel.Text = string.Format( "File '{0}' uploaded successfully to Azure BLOB storage.<br/>Start: {1}<br/>End: {2}<br/>Size: {3}",
               e.File.FileName, startDate.ToString(), DateTime.Now.ToString(), e.File.ContentLength.ToString() );
       }

Could this be the reason for not firing?

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Eric
Top achievements
Rank 1
answered on 01 Nov 2013, 09:01 PM
Hi Vance,

You can automatically trigger a postback when the upload finishes by capturing the OnClientFilesUploaded JavaScript event.  That should make fire off the event handler.

Otherwise, add a button that appears, which says something like "Save Uploads" or something. That would also trigger the server side event.

-Eric
Tags
CloudUpload
Asked by
Vance Smith
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Eric
Top achievements
Rank 1
Share this question
or