Selecting video from photo library broken in UIWebView/WKWebView

Originator:aertmann
Number:rdar://28016475 Date Originated:25-Aug-2016
Status:Open Resolved:
Product:Safari Product Version:9.3.4
Classification: Reproducible:Always
 
Using a WKWebView/UIWebView with a file input element that allows for multiple selection (<input type="file" multiple />) doesn't work when selecting videos. This seems to be due to the fact that videos selected this way are not "compressed" and thus not accessible/readable in the same way they are when only selecting a single video.

It works fine with newly recorded videos or when it doesn't allow multiple selection.

Steps to Reproduce:
Create an app with a WKWebView/UIWebView and the following HTML

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <title>Broken video selection</title>
    </head>
    <body>
        <h1>Choose video</h1>
        Single (works): <input type="file" /><br /><br />
        Multiple (broken): <input type="file" multiple />
        <script>
            var inputs = document.getElementsByTagName('input');
            for (var i = inputs.length; i--;) {
                inputs[i].onchange = function(e) {
                    var file = e.target.files[0];
                    var fileReader = new FileReader();
                    fileReader.onload = function() {
                        console.log('Succesfully read file', file.name);
                    }
                    fileReader.onerror = function(e) {
                        console.error('Error reading file', e, file);
                    }
                    fileReader.readAsDataURL(file);
                };
            };
        </script>
    </body>
</html>


Expected Results:
That the video files would behave like the other file types that can be selected, similar to how it works if only single file selection of a video does.

Actual Results:
An unreadable file that cannot be uploaded.

The onerror throws a "ProgressEvent" from the "FileReader" with the following "FileError" with code "1" meaning "NOT_FOUND_ERR".
In WkWebView the error code is "4" (NOT_READABLE_ERR) instead of "1"

Same code works fine in a normal iOS Safari web view.

Comments

it's also broken on SafariVC


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!