From c03fd66aeb8a6f10290381a76db0867fabe881e6 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Fri, 5 Jun 2020 16:01:22 -0600 Subject: [PATCH] Support new onUpload() AJAX handler for uploads instead of postback takeovers. Fixes #5104. Refs: https://github.com/octobercms/october/commit/4f7e2995c72298c522a27bf162f8f5e7316d9417 --- modules/cms/widgets/AssetList.php | 10 +++++----- modules/cms/widgets/assetlist/assets/js/assetlist.js | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/cms/widgets/AssetList.php b/modules/cms/widgets/AssetList.php index 3dda5d1b3..a37643560 100644 --- a/modules/cms/widgets/AssetList.php +++ b/modules/cms/widgets/AssetList.php @@ -57,8 +57,6 @@ class AssetList extends WidgetBase parent::__construct($controller, []); $this->bindToController(); - - $this->checkUploadPostback(); } /** @@ -622,10 +620,12 @@ class AssetList extends WidgetBase } /** - * Checks the current request to see if it is a postback containing a file upload - * for this particular widget. + * Process file uploads submitted via AJAX + * + * @return void + * @throws ApplicationException If the file "file_data" wasn't detected in the request or if the file failed to pass validation / security checks */ - protected function checkUploadPostback() + public function onUpload() { $fileName = null; diff --git a/modules/cms/widgets/assetlist/assets/js/assetlist.js b/modules/cms/widgets/assetlist/assets/js/assetlist.js index f430c669c..4fb3d41cc 100644 --- a/modules/cms/widgets/assetlist/assets/js/assetlist.js +++ b/modules/cms/widgets/assetlist/assets/js/assetlist.js @@ -83,6 +83,9 @@ } AssetList.prototype.onUploadFail = function(file, message) { + if (file.xhr.status === 413) { + message = 'Server rejected the file because it was too large, try increasing post_max_size'; + } if (!message) { message = 'Error uploading file' } @@ -170,6 +173,7 @@ $.each(self.$form.serializeArray(), function (index, field) { formData.append(field.name, field.value) }) + xhr.setRequestHeader('X-OCTOBER-REQUEST-HANDLER', self.alias + '::onUpload') self.onUploadStart() }) }