]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix IE11 upload fallback methods 20602/head
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Wed, 22 Apr 2020 11:40:23 +0000 (13:40 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 22 Apr 2020 20:09:06 +0000 (20:09 +0000)
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
apps/files/js/file-upload.js

index b987fa4e42b040547eabe4099ed18ce5817c9266..f21de9a20697f5f1eab0ebe20a007fe1cf6da1d3 100644 (file)
@@ -44,6 +44,28 @@ OC.FileUpload = function(uploader, data) {
 OC.FileUpload.CONFLICT_MODE_DETECT = 0;
 OC.FileUpload.CONFLICT_MODE_OVERWRITE = 1;
 OC.FileUpload.CONFLICT_MODE_AUTORENAME = 2;
+
+// IE11 polyfill
+// TODO: nuke out of orbit as well as this legacy code
+if (!FileReader.prototype.readAsBinaryString) {
+       FileReader.prototype.readAsBinaryString = function(fileData) {
+               var binary = ''
+               var pt = this
+               var reader = new FileReader()
+               reader.onload = function (e) {
+                       var bytes = new Uint8Array(reader.result)
+                       var length = bytes.byteLength
+                       for (var i = 0; i < length; i++) {
+                               binary += String.fromCharCode(bytes[i])
+                       }
+                       // pt.result  - readonly so assign binary
+                       pt.content = binary
+                       $(pt).trigger('onload')
+               }
+               reader.readAsArrayBuffer(fileData)
+       }
+}
+
 OC.FileUpload.prototype = {
 
        /**
@@ -938,12 +960,13 @@ OC.Uploader.prototype = _.extend({
 
                                        // in case folder drag and drop is not supported file will point to a directory
                                        // http://stackoverflow.com/a/20448357
-                                       if ( ! file.type && file.size % 4096 === 0 && file.size <= 102400) {
+                                       if ( !file.type && file.size % 4096 === 0 && file.size <= 102400) {
                                                var dirUploadFailure = false;
                                                try {
                                                        var reader = new FileReader();
                                                        reader.readAsBinaryString(file);
-                                               } catch (NS_ERROR_FILE_ACCESS_DENIED) {
+                                               } catch (error) {
+                                                       console.log(reader, error)
                                                        //file is a directory
                                                        dirUploadFailure = true;
                                                }
@@ -1059,6 +1082,7 @@ OC.Uploader.prototype = _.extend({
                                                                message = response.message;
                                                        }
                                                }
+                                               console.error(e, data, response)
                                                OC.Notification.show(message || data.errorThrown, {type: 'error'});
                                        }