Getting problem with getting the byte[] file

2 posts, 0 answers
  1. Jan Michael
    Jan Michael avatar
    13 posts
    Member since:
    Oct 2008

    Posted 02 Jul 2009 Link to this post

    Hi, I'm expreriencing problem getting the right size of the file in byte[].
    Here's my scenario: I'm uploading the file and then get the byte[] size and save it to db. When i try to upload a e.g. 4mb docx file then it goes to my Raduploadhandler.ashx, I only get the 56kb file size. Is there something wrong with my upload handler?

    public class RadUploadHandler : Telerik.Windows.RadUploadHandler   
    {  
        Dictionary<string, object> dict = new Dictionary<string, object>();  
          
        public override void ProcessStream()     
        {     
            string submissionID = Request.Form["SubmissionID"];  
              
            string submitter = Request.Form["UserAlias"];  
          
            byte[] assetData = Convert.FromBase64String(Request.Form["RadUAG_data"]);     
        
            this.AddReturnParam("RadUAG_associatedData", "");     
        
            this.AddReturnParam("RadUAG_finalFileRequest", this.IsFinalFileRequest());     
        
            this.AddReturnParam("RadUAG_success", true); // or false if something fails       
        
            this.AddReturnParam("RadUAG_message", "");// or add an error message if it is needed       
        
            string fileName = this.Request.Form["RadUAG_fileName"];     
        
            string filePath = this.GetFilePath(fileName);     
        
            this.AddReturnParam("RadUAG_fileIdent", filePath);     
        
            this.AddReturnParam("RadUAG_fileName", fileName);     
        
            this.AddReturnParam("RadUAG_filePath", filePath);  
     
            if (IsFinalFileRequest())  
            {  
                byte[] buffer = Convert.FromBase64String(this.Request.Form["RadUAG_data"]);  
                long attachmentID = SaveFileToDB(buffer, fileName, Convert.ToInt64(submissionID), submitter);  
                dict.Add("AttachmentID", attachmentID);  
                string associatedDataString = String.Empty;  
                if (dict.Count > 0)  
                {  
                    foreach (string key in dict.Keys)  
                    {  
                        object value = dict[key];  
                        if (value == null)  
                        {  
                            value = "null";  
                        }  
     
                        value = "\"" + value.ToString().Replace("\\", "\\\\") + "\"";  
                        associatedDataString += "{" + String.Format(@"""Key"":""{0}"",""Value"":{1}", key, value) + "},";  
                    }  
     
                    associatedDataString = associatedDataString.TrimEnd(',');  
                }  
                this.AddReturnParam("RadUAG_associatedData", associatedDataString);  
            }  
     
     
        } 

  2. Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 02 Jul 2009 Link to this post

    Hi Jan Michael,

    This is because of uploading files in a small parts - chunks. When you get the uploaded information (a chunk) you need its position too. Use the code below to extract the position from the upload parameters:

    long position = Convert.ToInt64(this.Request.Form[RadUploadConstants.ParamNamePosition]); 


    Please preview the following articles, where we are demonstrating techniques for manipulation of uploaded files:

    We hope this information will help you.

    All the best,
    Ivan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
Back to Top