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

MIME types

3 Answers 82 Views
Upload
This is a migrated thread and some comments may be shown as answers.
G
Top achievements
Rank 1
G asked on 01 Jun 2009, 09:50 AM
 Is there anyway in that Silverlight Upload can return the MIME type of a file that has been uploaded?

3 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 03 Jun 2009, 12:09 PM
Hello G,

Thank you for the interest in our RadUpload control.

Generally there are two parts that work together in the upload process: the RadUpload control (at client side) and the upload handler (at server side). You should decide where the check-code will reside - for example:
  1. if you put the check-code at server side (in upload handler) you should return the MIME type as a custom parameter from the upload handler. More information you can find in the Returning custom data from the handler article.
  2. if you put the mine-check-code at the client side you should run it inside the FileUploaded event-handler. Note all the information about the uploaded file and the status of the upload itself are in the FileUploadedEventArgs argument (the second one), for example:

    private void RadUpload1_FileUploaded(object sender, FileUploadedEventArgs e) 
        if (e.HandlerData.IsSuccess) 
        { 
            ExploreMIME.GetType(e.SelectedFile.File); 
    . . . 
Please give it a try and let me know if you need more assistance.

Sincerely yours,
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.
0
KDL
Top achievements
Rank 1
answered on 17 Apr 2012, 01:33 AM
I know this is an old thread but I'm having the same problem. I need to know the MIME type of the file and this post indicates that it's available. The example given didn't work for me. I am able to pass values between the RadUpload control and the Handler without a problem, but I'm just not seeing how to get the mime type in the first place. Thanks!
0
Tina Stancheva
Telerik team
answered on 19 Apr 2012, 02:01 PM
Hello Kent,

The RadUpload control doesn't expose a method or property which can give you the MIME type, but you can create a custom method for finding the MIME type of a file based on its extension for example. You can have a look at this thread where different approaches, for getting the MIME type of a file, are discussed.

Regardless of the approach you choose for getting the MIME type, it would be best to place the logic on the server-side part of the RadUpload control. You can override the SaveChunkData method and as soon as the entire file is uploaded, implement a custom method to get its MIME type:
string MIMEType;
      public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
      {
          bool result = base.SaveChunkData(filePath, position, buffer, contentLength, out savedBytes);
 
          if (this.IsFinalFileRequest())
          {
              FileInfo fi = new FileInfo(filePath);
              MIMEType = GetMimeType(fi);
          }
          return result;
      }

Then you can use the MIME type on the server or pass it to the client by overriding the GetAssociatedData() method. I attached a sample project to get you started, please give it a try and let me know if it helps.

Greetings,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Upload
Asked by
G
Top achievements
Rank 1
Answers by
Ivan
Telerik team
KDL
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or