Check for MIME types

Last post 05-30-2013, 3:57 AM by Ardalan. 6 replies.
Sort Posts: Previous Next
  •  05-24-2013, 4:14 AM 77479

    Check for MIME types

    Hi,

     

    There is no documentation for ValidateOption.AllowedFileMimeTypes. How can I use this property to limit the file types a user can upload? And more importantly, where can I set the error message shown to the user if he/she uploads a file with an invalid type?

     

    Thanks. 

  •  05-24-2013, 12:37 PM 77484 in reply to 77479

    Re: Check for MIME types

    Hi Ardalan,

     

    1. To limit the upload file extension, I suggest you set "AllowedFileExtensions".

     

      <ValidateOption  AllowedFileExtensions="jpg,gif,txt"/> 

     

    2. Please refer to http://www.ajaxuploader.com/document/scr/html/How-to-catch-uploader-error.htm, it shows you how to catch the uploader error then shows you custom error message.

     

    Regards,

     

    Ken 

  •  05-28-2013, 7:01 AM 77493 in reply to 77484

    Re: Check for MIME types

    Hi Ken,

     

    I want to check the MIME type because the user can easily bypass the file extension validation by renaming the file. Does this control support MIME type checking?

  •  05-28-2013, 12:08 PM 77497 in reply to 77493

    Re: Check for MIME types

    Hi Ardalan,

     

    Yes, just need to set EnableMimetypeChecking to true.

     

      <ValidateOption EnableMimetypeChecking="true" /> 

     

    Regards,

     

    Ken 

  •  05-29-2013, 4:41 AM 77499 in reply to 77497

    Re: Check for MIME types

    How can I specify which MIME types to check? That was my initial question. How do I set the ValidateOption.AllowedFileMimeTypes property? Would you please give me an example?

     

    Also, this link that you provided (http://www.ajaxuploader.com/document/index.htm#page=html/How-to-catch-uploader-error.htm) does not give specific instructions on how to catch the MIME error. What do the parameters of the CuteWebUI_AjaxUploader_OnTaskError event do? How can I know if this is the MIME error?

    CuteWebUI_AjaxUploader_OnTaskError(obj,msg,reason)
     

  •  05-29-2013, 12:21 PM 77505 in reply to 77499

    Re: Check for MIME types

    Hi Ardalan,

     

    1. set the mime type like below

     

      <ValidateOption AllowedFileMimeTypes="image/gif,image/jpeg" />

     

    2. The mime type error message is "The file is corrupt or has an incorrect extension. ", you can catch this message link below, then shows your custom error.

     

    <script type="text/javascript">
        function CuteWebUI_AjaxUploader_OnError(msg) {
            if (msg.indexOf("The file is corrupt or has an incorrect extension") != -1) {
                //show the message you want
                alert("The file is locked");
                return false;
            }
        }
    </script>
     

    Regards,

     

    Ken 

  •  05-30-2013, 3:57 AM 77510 in reply to 77505

    Re: Check for MIME types

    Thanks, Ken. This fixed the issue.
View as RSS news feed in XML