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

2 posts, 0 answers
  1. Nathi Mfeka
    Nathi Mfeka avatar
    16 posts
    Member since:
    Aug 2009

    Posted 16 May 2011 Link to this post

    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,
  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 19 May 2011 Link to this post

    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
  3. DevCraft banner
Back to Top