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'.
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