This is a migrated thread and some comments may be shown as answers.

Upload splits large files into chunks, how do i save the whole file into the DB?

1 Answer 291 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Nathi Mfeka
Top achievements
Rank 2
Nathi Mfeka asked on 16 May 2011, 12:01 PM

Hi guys

I understand that the Upload Handler splits files into chunks by design, in my case its splitting a 4 MB file into like 40 chunks and saving them to the DB, without using the BufferSize Property how can i save the whole file? or rather how do these chunks add up to my original file?

I've tried doing somthing like the below code, now my only problem with this is that its only taking the last Chunk and saving it to the DB?

public override void ProcessStream()
    {
        base.ProcessStream();
        if(IsFinalFileRequest())
        {
            var entity = Int16.Parse(Request.Form["0_SysEntityID"]);
            var userID = Int64.Parse(Request.Form["0_UserID"]);
            var itemID = Int64.Parse(Request.Form["0_ItemID"]);
            var document = Request.Form["0_Filename"];


            var ext = document.Substring(document.LastIndexOf("."));
            var documentName = document.Replace("." + ext"");


            var contentLength = Request.Files[0].ContentLength;
            var mimeType = Request.Files[0].ContentType;
            var content = new byte[contentLength];
            Request.Files[0].InputStream.Read(content0contentLength);

            SqlUtilities.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString,
                "Pr_DocumentInsert",
                CommandType.StoredProcedure,
                new SqlParameter("@DocumentName"documentName),
                new SqlParameter("@DocumentExt"ext),
                new SqlParameter("@DocumentContent"content),
                new SqlParameter("@DocumentSize"contentLength),
                new SqlParameter("@MimeType"mimeType),
                new SqlParameter("@SysEntityID"entity),
                new SqlParameter("@ItemID"itemID),
                new SqlParameter("@UserID"userID)); 
        }

Your help in this regard will be highly apreciated,

1 Answer, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 19 May 2011, 08:13 AM
Hi Nathi Mfeka,

On the server side, the RadUploadHandler opens the file and add the uploaded bytes to the file's stream and that is how each chunk is added to the file. In the SaveChunkData method, you can check the result of the IsFinalFileRequest method. If it returns true, the the whole file is uploaded and you can use it on the server side.

Regards,
Alex Fidanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Upload
Asked by
Nathi Mfeka
Top achievements
Rank 2
Answers by
Alex Fidanov
Telerik team
Share this question
or