Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:08:43+00:00 2026-05-31T22:08:43+00:00

Is there a way to use the HttpPostedFileBase elements to find out if its

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:08:44+00:00Added an answer on May 31, 2026 at 10:08 pm

    If you want to be absolutely certain, it is best to check the stream of the HttpPostedFileBase for 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:

    public static bool IsMP4(System.IO.Stream stream)
    {
        return HasMagicBytes(stream, 0, 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x70, 0x34);
    }
    
    public static bool HasMagicBytes (System.IO.Stream stream, int offset, params byte[] magicBytes)
    {
        try {
            bool match = false;
            byte[] bytes = new byte[magicBytes.Length];
            if (stream.Read (bytes, offset, magicBytes.Length) == magicBytes.Length) {
                for (int i = 0; i < magicBytes.Length; i++) {
                    if (bytes [i] != magicBytes [i]) {
                        return false;
                    }
                }   
                return true;
            } else {
                return false;
            }
    
        } finally {
            stream.Seek (0, System.IO.SeekOrigin.Begin);
        }
    
    }
    

    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:

    public class MyModel
    {
        [CheckFormat(0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x70, 0x34)]
        public HttpPostedFileBase MyFile { get; set; }
    }
    

    But I’ll leave that to you to investigate further.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to use two HTML5 video tags on a page and
Is there a way use STL containters with non-copyable elements? something like this: class
Is there way to use the Find in Files command for searching all of
Is there any way to use the fade in/out effect of jQuery while loading
Is there a way to use jQuery to figure out the type of width
Is there any way to use a php file in the parent folder. I
Is there any way to use inheritance in database (Specifically in SQL Server 2005)?
Is there a way to use JQuery to cloak or encrypt email addresses on
Is there any way to use a constant as a hash key? For example:
Is there a way to use constants in JavaScript ? If not, what's the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.