I would like to use RadAsyncUpload control to upload multiple files to Amazon S3. I have included RadAsyncUpload control in my web application. I am able to select multiple files to upload and it uploads the selected files successfully to Amazon S3 ( it stores the files temporarily to temp folder) but when I try to download files from amazon S3, I get the corrupted file as the contenttype of the file never gets set properly. I am using the serverside event . "FileUploaded" to get the selected file's name, content type and content length. The content length is returned as an integer and when I convert that into the byte(), it gives me the wrong result. Here is my code:
Protected Sub RadAsyncUpload1_FileUploaded(ByVal sender As Object, ByVal e As Telerik.Web.UI.FileUploadedEventArgs) Handles RadAsyncUpload1.FileUploaded
Dim counter As Integer = Session("counter")
Dim newrow As DataRow = dt.NewRow
Dim buffer As Byte() = New Byte(e.File.ContentLength - 1) {}
If e.IsValid Then
S3Conn = New AWSAuthConnection(S3AWSAccessKeyId, S3SecretAccessKeyId)
counter = counter + 1
If Not S3Conn Is Nothing Then
S3Conn.createBucket(S3Bucket, Nothing)
Dim metadata As SortedList = New SortedList()
metadata.Add("filename", e.File.FileName)
Dim s3key As String = "test/" & Session("dbid") & "_" & Session("recid") & "_" & CStr(counter)
Dim obj As S3Object = New S3Object(buffer, metadata)
Dim headers As New SortedList
headers.Add("Content-Type", buffer)
headers.Add("x-amz-acl", "public-read")
S3Conn.put(S3Bucket, s3key, obj, headers)
End If
Session("counter") = counter
S3Conn = Nothing
End If
End Sub