Is there a way to use the HttpPostedFileBase elements to find out if its a valid video file fomart (except of validating the extension). Im using aspnet mvc 3 by the way.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to be absolutely certain, it is best to check the stream of the
HttpPostedFileBasefor magic bytes. This is because some applications may write it as an extension that you think you can process (such as MP4), but in reality it is another format such as M4V.For example, to check if a stream is an MP4 variation stream, you can check if the stream starts with the bytes 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x70 and 0x34. You can find more formats here.
Something like this may work:
Some care should be taken whether the stream is seekable. This technique is rather efficient for larger files. To make this reusable, you can write a ValidationAttribute so it may be possible to define your model like this:
But I’ll leave that to you to investigate further.