Get file info before upload

4 posts, 1 answers
  1. Kennet
    Kennet avatar
    104 posts
    Member since:
    Jun 2009

    Posted 21 Sep 2009 Link to this post

    How can I get info from the file I selecct before I upload it.

    Example I only want to upload picture bigger than a specific size, or in my case upload mp3 with a specific bitrate?

  2. Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 22 Sep 2009 Link to this post

    Hello Kennet,

    Thank you for your interest in the RadUpload control.

    The upload control provide some basic filters right of the box - MaxFileCount, MaxFileSize, MaxUploadSize. If you need some more sophisticated filter then you should rely on the FileSelected event - here you can access the FileInfo structure for all the selected files. In the attached example we are filtering against the minimum size of 4kB.

    Please give it a try and let us know if there are more questions.

    Sincerely yours,
    Ivan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Kennet
    Kennet avatar
    104 posts
    Member since:
    Jun 2009

    Posted 28 Sep 2009 Link to this post

    Thanks,

    But is there any way to access the file from Silverlight before uploading it, I can't get the path for the file?

    In this case I want to read some info from a MP3 file, like the bitrate, and only upload files with a certain bitrate.

    for (int index = e.SelectedFiles.Count; index-- > 0; )  
                {  
                      
     
                    RadUploadSelectedFile file = e.SelectedFiles[index];  
     
                    MP3Header mp3hdr = new MP3Header();  
                    bool boolIsMP3 = mp3hdr.ReadMP3Information(file.File.Name);  
                    if (boolIsMP3)  
                    {  
                        lbox1.Items.Add(mp3hdr.strFileName);  
                        lbox1.Items.Add(mp3hdr.lngFileSize.ToString());  
                        lbox1.Items.Add(mp3hdr.intBitRate.ToString());  
                        lbox1.Items.Add(mp3hdr.intFrequency.ToString());  
                        lbox1.Items.Add(mp3hdr.strMode);  
                        lbox1.Items.Add(mp3hdr.strLengthFormatted);  
                        lbox1.Items.Add(mp3hdr.intLength.ToString());  
                        lbox1.Items.Add("===========================");  
                    }  

    The MP3 Class is found here:

    http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=79
  5. Answer
    Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 01 Oct 2009 Link to this post

    Hello Kennet,

    In the Silverlight environment you can not access the file's full name - this is a security limitation of the Framework. The good news is that there is a way to read data from a local file - you should operate in FilesUpload even handler - relying on the FileInfo structure (supplied by the Silverlight). Below is a sample code:

    private void radUpload_FilesSelected(object sender, FilesSelectedEventArgs e) 
        foreach (RadUploadSelectedFile radFile in e.SelectedFiles) 
        { 
            FileInfo fileInfo = radFile.File; 
            Stream fileStream = fileInfo.OpenRead(); 
            long fileSize = fileStream.Length; 
            int bufferSize = 4096; 
            byte[] buffer = new byte[bufferSize]; 
            for (int position = 0; position < fileSize; ) 
            { 
                int delta = fileStream.Read(buffer, position, bufferSize); 
                if (delta > 0) 
                { 
                    // Process your data here; 
                } 
                position += delta; 
            } 
            fileStream.Close(); 
        } 

    We hope this information will help you.

    Best wishes,
    Ivan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top