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

Getting problem with getting the byte[] file

1 Answer 72 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Jan Michael
Top achievements
Rank 1
Jan Michael asked on 02 Jul 2009, 01:07 PM
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);  
        }  
 
 
    } 

1 Answer, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 02 Jul 2009, 02:49 PM
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.
Tags
Upload
Asked by
Jan Michael
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Share this question
or