I have an upload form for an video. The user clicks browse and selects a file. How can I get the video dimensions the moment the user selects开发者_StackOverflow中文版 the file (before the file is even uploaded to the server). It obviously has to be something client-side with maybe javascript/jquery or flash/flex (prefer js//jquery though), but can either of them do this?
Unfortunately, the short answer is you can't - You'd need access to scan the file contents using javascript which isn't allowed. Worse than that, even if you could read the file somehow, you'd need to implement a whole host of codecs in JS just to read the header information.
Mark this one as not possible
In theory you should be able to use the FileReader API - https://developer.mozilla.org/en/DOM/FileReader
Once the file has been read, you can parse out the headers. As far as I know, nobody has ever done this in javascript.
This is a very old question but now it's possible to know video dimensions on client side before upload.
Refer to this question: HTML5 Video Dimensions
Example code:
var v = document.getElementById("myVideo");
v.addEventListener( "loadedmetadata", function (e) {
var width = this.videoWidth,
height = this.videoHeight;
}, false );
If dimensions is resolution: no
If dimensions is file-size: (now) yes:
Using jQuery, Restricting File Size Before Uploading
精彩评论