MIME types

4 posts, 0 answers
  1. G
    G avatar
    4 posts
    Member since:
    Apr 2009

    Posted 01 Jun 2009 Link to this post

     Is there anyway in that Silverlight Upload can return the MIME type of a file that has been uploaded?
  2. Ivan
    Ivan avatar
    519 posts

    Posted 03 Jun 2009 Link to this post

    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) 
      . . . 
    Please give it a try and let me know if you need more assistance.

    Sincerely yours,
    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. KDL
    KDL avatar
    36 posts
    Member since:
    Aug 2005

    Posted 16 Apr 2012 Link to this post

    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!
  4. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 19 Apr 2012 Link to this post

    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.

    Tina Stancheva
    the Telerik team

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

Back to Top