Updated Example Needed - Server cancel upload and return custom error message to client

10 posts, 1 answers
  1. iCeMAn
    iCeMAn avatar
    5 posts
    Member since:
    Nov 2010

    Posted 24 Nov 2010 Link to this post

    Hi guys,

    In this post you provided an example demonstrating how to return a custom message to the client using the RadUpload control. I tried following the code but unfortunately it appears it was written for an earlier version of the RadUpload control. The constants RadUploadConstants.ParamNameFileIdent and RadUploadConstants.ParamNameFilePath no longer exist. Can you please provide an updated example using the Q2 2010 controls (or later)? Please make it simple just like the example I mentioned earlier.

    Thanks in advance.
  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 25 Nov 2010 Link to this post

    Hi iCeMAn,

    You can see an updated code example of the same functionality in our help here. Please let us know if you need further assistance with this.

    Greetings,
    Alex Fidanov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. iCeMAn
    iCeMAn avatar
    5 posts
    Member since:
    Nov 2010

    Posted 25 Nov 2010 Link to this post

    Thanks for the response.

    I read that help topic already and tried to follow the code but could not get it to work. I then searched your site for examples and found one, but unfortunately it was built using an older version of the controls. I'll get straight to the point with my problem.

    I have the following code in my upload handler:

    Public Overrides Function SaveChunkData(ByVal filePath As String, ByVal position As Long, ByVal buffer() As Byte, ByVal contentLength As Integer, ByRef savedBytes As Integer) As Boolean
        Dim _result As Boolean = MyBase.SaveChunkData(filePath, position, buffer, contentLength, savedBytes), _
            _returnMessage As String, _
            _fileName As String
     
        'was chunk successfully saved?
        If _result Then
            If IsFinalUploadRequest() Then
                'process uploaded files
                _returnMessage = ProcessUploadedFiles()
                If Not String.IsNullOrEmpty(_returnMessage) Then 'file processing failed
                    'file processing failed
                    _result = False
     
                    'return custom message to client
                    _fileName = GetQueryParameter(RadUploadConstants.ParamNameFileName)
                    AddReturnParam(RadUploadConstants.ParamNameMessage, _returnMessage)
                    AddReturnParam(RadUploadConstants.ParamNameSuccess, False)
                    AddReturnParam(RadUploadConstants.ParamNameFileName, _fileName)
                    AddReturnParam(RadUploadConstants.ParamNameFinalFileRequest, True)
                End If
            End If
        End If
     
        'was file successfully processed?
        Return _result
    End Function

    I also have this code on the client:

    Private Sub ucManifest_FileUploadFailed(ByVal sender As Object, ByVal e As FileUploadFailedEventArgs) Handles ucManifest.FileUploadFailed
        If e.HandlerData.IsSuccess Then
            'successful upload
        ElseIf Not String.IsNullOrEmpty(e.HandlerData.Message) Then
            e.ErrorMessage = e.HandlerData.Message
        ElseIf e.HandlerData.CustomData.Count = 0 Then
            'custom data empty
        Else
            'TODO: display custom data
        End If
    End Sub

    In my handler, when the statement _returnMessage = ProcessUploadedFiles() is executed and processing fails (for whatever reason), the details are stored in the _returnMessage variable. At present, if file processing fails, e.HandlerData.Message and e.HandlerData.CustomData are both empty. I wish to populate either of these fields with the value of _returnMessage  from the server side so that I can display a custom message at the client. How do I achieve this?
  5. Answer
    Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 30 Nov 2010 Link to this post

    Hello iCeMAn,

    I apologize for the delayed response. Please try using the AddReturnFileParam method instead of AddReturnParam and let us know if the ErrorMessage property of the event args of the FileUploadFailed event or the HandlerData are still empty.

    Greetings,
    Alex Fidanov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  6. iCeMAn
    iCeMAn avatar
    5 posts
    Member since:
    Nov 2010

    Posted 03 Dec 2010 Link to this post

    Yes that did the trick! The ErrorMessage property is no longer empty, which is sufficient for my project. The HandlerData property is still empty but I'll toy around with that some more. I have two remaining questions:

    1. What's the difference between AddReturnFileParam and AddReturnParam?
    2. How do I know which one to use?

    Thanks again.
  7. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 04 Dec 2010 Link to this post

    AddReturnFileParam does return things specificaly for a given file. It calls AddReturnParam.

    What I want to ask is if AddReturnParam is does for us to use or is only internal.
    How can the things returned throught AddReturnParam be read on the client?
  8. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 08 Dec 2010 Link to this post

    Hi John,

    The messages returned to the client can be accessed in the Handler data of the event arguments. For example, in FileUploaded or FileUploadFailed event, you will be able to get the message through the e.HandlerData property. You should use AddReturnFileParam if the message is specific to a file.

    Kind regards,
    Alex Fidanov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  9. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 08 Dec 2010 Link to this post

    Hello Alex,
    Thank you for your help.
    In the meantime you already got my detailed report about what I found unclear in your documentation ;)
    Kind regards,
    John.
  10. mark
    mark avatar
    6 posts
    Member since:
    Jul 2011

    Posted 15 Dec 2011 Link to this post

    I have extensively modified the RadFileUploader to support high scale distributed uploading on Windows Azure blob storage. In order to do this, I save chunks temporarily into blob storage and then merge at the end. Saving to local storage on the server is not scalable as I cannot garauntee that all upload requests will hit the same server in Windows Azure if I have >1 instance running.

    Therefore, when I recognize this is the first chunk of a file I generate a unique ID that will be its final merged filename in BLOB storage. When I reach the final chunk to save, I perform the merge on all the parts stored in temporary blob storage into a single blob with a filename of this unique ID that I originally generated.

    The Problem: My Silverlight client does not know about this unique ID because it is generated during the save chunking process server side.

    EXPECTED RESULTS: I use AddReturnFileParamto send the unique ID back down to the client and retrieve this unique ID from the FileUploadEventArgs.HandlerData.CustomData property on the event args of the FileUploaded event.

    ACTUAL RESULTS: I use AddReturnFileParamto send the unique ID back down to the client and retrieve this unique ID from the FileUploadEventArgs.HandlerData.CustomData property on the event args of the FileUploaded event. But the CustomData dictionary is EMPTY.


  11. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 20 Dec 2011 Link to this post

    Hi Mark,

    In order to return the ID to the client and access it through the FileUploadEventArgs.HandlerData.CustomData property, you'll have to override the RadUploadHandler GetAssociatedData method and add the ID to the Dictionary it defines. This method prepares a dictionary for associated (custom) data returned to the client on each Final-file-request.

    You can find more information about returning parameters to the server here. Please give this approach a try and let us know how it goes.

    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