sunhater / kcfinder

KCFinder web file manager
http://kcfinder.sunhater.com
402 stars 209 forks source link

Upload cancelled in Chrome 83.0.4103.61 #185

Open chocolata opened 4 years ago

chocolata commented 4 years ago

After updating Chrome to the most recent version (83.0.4103.61 in my case), the upload function of KCfinder seems to be broken. You can select a file, but immediately after the upload starts, it is cancelled. See enclosed screenshot. Does anyone have a solution for this? Should we hope that it is a bug in Chrome or is this wishful thinking? Thanks in advance. Inkedunnamed_LI

Strangely, dragging and dropping files to upload seems to be unaffected...

lowbatteries commented 4 years ago

I'm having this issue as well in Chrome 83 (not present in Chrome 81), and am trying to find a solution. The bug also happens in the beta Chrome 85, so I don't think it will go away with a Chrome update.

chocolata commented 4 years ago

Thanks for your response. Keep us posted if you find anything. I'm looking for a solution aswel. In the JavaScript-files I regularly encounter async: false; regarding AJAX requests. Could this have anything to do with it?

I've been looking here, at the moment in vain: https://developers.google.com/web/updates/2020/04/chrome-83-deps-rems

lowbatteries commented 4 years ago

I think I've found it. js/browser/toolbar.js, the $('#uploadResponse').load function is being fired immediately when it is created, short-circuiting the upload process.

Removing the src attributes from this iframe fixes it: $('<iframe id="uploadResponse" name="uploadResponse" src="javascript:;"></iframe>').

chocolata commented 4 years ago

Hi @lowbatteries thank you so much for this. I can confirm that this also fixes it for me! You wouldn't be up to forking this library and maintaining it, would you?

sergey-dryabzhinsky commented 4 years ago

You can try this fix:

--- toolbar.js.old  2014-03-12 02:33:27.000000000 +0400
+++ toolbar.js  2020-05-27 15:28:31.951677064 +0300
@@ -142,31 +142,39 @@
         return;
     }
     form.elements[1].value = browser.dir;
-    $('<iframe id="uploadResponse" name="uploadResponse" src="javascript:;"></iframe>').prependTo(document.body);
     $('#loading').html(this.label("Uploading file..."));
     $('#loading').css('display', 'inline');
-    form.submit();
-    $('#uploadResponse').load(function() {
-        var response = $(this).contents().find('body').html();
-        $('#loading').css('display', 'none');
-        response = response.split("\n");
-        var selected = [], errors = [];
-        $.each(response, function(i, row) {
-            if (row.substr(0, 1) == '/')
-                selected[selected.length] = row.substr(1, row.length - 1)
-            else
-                errors[errors.length] = row;
-        });
-        if (errors.length)
-            browser.alert(errors.join("\n"));
-        if (!selected.length)
-            selected = null
-        browser.refresh(selected);
-        $('#upload').detach();
-        setTimeout(function() {
-            $('#uploadResponse').detach();
-        }, 1);
-        browser.initUploadButton();
+/* Fix new Chrome */
+    var post = new FormData(form);
+    $.ajax({
+        url: $(form).attr('action'),
+        type: 'POST',
+        data: post,
+        processData: false,
+        contentType: false,
+        cache: false,
+        success: function(data) {
+            $('#loading').css('display', 'none');
+
+            response = data.split("\n");
+            var selected = [], errors = [];
+            $.each(response, function(i, row) {
+                if (row.substr(0, 1) == '/')
+                    selected[selected.length] = row.substr(1, row.length - 1)
+                else
+                    errors[errors.length] = row;
+            });
+            if (errors.length)
+                browser.alert(errors.join("\n"));
+            if (!selected.length)
+                selected = null
+            browser.refresh(selected);
+            $('#upload').detach();
+        },
+        error: function(e) {
+            $('#loading').css('display', 'none');
+            browser.alert("Can't upload file!\nSever error!");
+        }
     });
 };
noorfathima5690 commented 4 years ago

Thank you, Removing src attribute from the iframe works, I changed in js/toolbar.js and cache/base.js

chocolata commented 4 years ago

Is there any way where we can get these fixes pushed into the repo?

lois333 commented 4 years ago

Thank you, works for me !

ufukucar commented 4 years ago

I think I've found it. js/browser/toolbar.js, the $('#uploadResponse').load function is being fired immediately when it is created, short-circuiting the upload process.

Removing the src attributes from this iframe fixes it: $('<iframe id="uploadResponse" name="uploadResponse" src="javascript:;"></iframe>').

Thanks. That solved my problem

finnef commented 4 years ago

FYI jquery upload was broken by the 19-02-2020 Chrome browser update 83.0.4103.61. https://bugs.chromium.org/p/chromium/issues/detail?id=1084874 Fixed in release from 03-06-2020 (83.0.4103.97)... phew.