This example illustrates the usage of RadAsyncUpload and BinaryImage and how to display and edit images. The upload process requires that the files are uploaded to a custom handler and not to the hosting page. Files are stored in a temporary location until a Postback occurs. The temporary location is cleaned-up automatically.
In order to save the uploaded files into the database you could use the InputStream property to access the content of the uploaded files:
.CS
....
UploadedFile file = radAsyncUpload.UploadedFiles[0];
byte[] fileData = new byte[file.InputStream.Length];
file.InputStream.Read(fileData, 0, (int)file.InputStream.Length);
cmd.Parameters.Add("@Data", SqlDbType.Image);
cmd.Parameters["@Data"].Value = fileData;
...
.VB
...
Dim file As UploadedFile = radAsyncUpload.UploadedFiles(0)
Dim fileData As Byte() = New Byte(file.InputStream.Length - 1) {}
file.InputStream.Read(fileData, 0, CInt(file.InputStream.Length))
cmd.Parameters.Add("@Data", SqlDbType.Image)
cmd.Parameters("@Data").Value = fileData
...
There are a few important things to consider when using RadAsyncUpload:
- RadAsyncUpload requires the Telerik.Web.UI.WebResource handler to be registered in the web.config
- You need to ensure that any submit buttons on the page are disabled while upload is in progress. Otherwise, there is no guarantee that the files will be uploaded successfully