RadAsyncUpload with custom handler fails for small files

2 posts, 0 answers
  1. M B
    M B avatar
    3 posts
    Member since:
    Nov 2006

    Posted 28 Nov 2012 Link to this post

    I am using RadAsyncUpload with a custom handler based on the demo code. The handler works fine with larger files that take more than a couple seconds to upload. When uploading smaller files that upload almost instantly I get the following error in the custom handler:
    Unable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream'.

    Protected Overrides Function Process(ByVal myFile As Telerik.Web.UI.UploadedFile, ByVal context As HttpContext, ByVal configuration As IAsyncUploadConfiguration, ByVal tempFileName As String) As IAsyncUploadResult
     
        Dim result As MyAsyncUploadResult = CreateDefaultUploadResult(Of MyAsyncUploadResult)(myFile)
        Try
     
          Dim userID As String = ""
     
          Dim myConfiguration As MyAsyncUploadConfiguration = TryCast(configuration, MyAsyncUploadConfiguration)
          If myConfiguration IsNot Nothing Then
            userID = myConfiguration.UserID
          End If
     
          result.FileID = MySaveFile(myFile, userID)
     
        Catch ex As Exception
          Dim sRtn As String = SendErrorEmail(ex, "", "", "handler.ashx", "", "", "")
        End Try
     
        Return result
      End Function
     
      Public Function MySaveFile(ByVal upFile As Telerik.Web.UI.UploadedFile, ByVal userID As String) As String
        Dim sOutputEncrypt As String = ""
        Dim destinationPath As String = "C:\sitefolder\App_Data\Files\"
        Try
          Dim key As Byte() = CreateKey("password")
          Dim IV As Byte() = CreateIV("password")
          Dim sFileName As String = upFile.FileName
          sOutputEncrypt = destinationPath & upFile.GetName.Replace(".", "_") & ".encrypt"
     
          Using fStream As FileStream = upFile.InputStream 'File.Open(filename, FileMode.OpenOrCreate)
            Dim RijndaelAlg As Rijndael = Rijndael.Create()
            Using cStream As New CryptoStream(fStream, RijndaelAlg.CreateEncryptor(key, IV), CryptoStreamMode.Read)
              Using destination As FileStream = File.Create(sOutputEncrypt)
                cStream.CopyTo(destination)
              End Using
            End Using
          End Using
     
         Catch ex As Exception
          Dim sRtn As String = SendErrorEmail(ex, "", "", "handler.ashx", "", "", "")
        End Try
        Return sOutputEncrypt
      End Function
  2. M B
    M B avatar
    3 posts
    Member since:
    Nov 2006

    Posted 28 Nov 2012 Link to this post

    Figured out my problem.
    Using fStream As FileStream = upFile.InputStream
     
    needs to be
     
    Using fStream As System.IO.Stream = upFile.InputStream

    Not sure why the original code worked for large files but not small ones.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top