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

Get file info before upload

3 Answers 125 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Kennet
Top achievements
Rank 2
Kennet asked on 21 Sep 2009, 08:30 AM
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?

3 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 22 Sep 2009, 12:42 PM
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.
0
Kennet
Top achievements
Rank 2
answered on 28 Sep 2009, 04:27 PM
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
0
Accepted
Ivan
Telerik team
answered on 01 Oct 2009, 06:48 AM
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.
Tags
Upload
Asked by
Kennet
Top achievements
Rank 2
Answers by
Ivan
Telerik team
Kennet
Top achievements
Rank 2
Share this question
or