diff --git a/modules/backend/formwidgets/FileUpload.php b/modules/backend/formwidgets/FileUpload.php index 2f75c3479..7deae0d99 100644 --- a/modules/backend/formwidgets/FileUpload.php +++ b/modules/backend/formwidgets/FileUpload.php @@ -113,7 +113,6 @@ class FileUpload extends FormWidgetBase } $this->getConfigFormWidget(); - $this->checkUploadPostback(); } /** @@ -410,15 +409,10 @@ class FileUpload extends FormWidgetBase } /** - * Checks the current request to see if it is a postback containing a file upload - * for this particular widget. + * Upload handler for the server-side processing of uploaded files */ - protected function checkUploadPostback() + public function onUpload() { - if (!($uniqueId = Request::header('X-OCTOBER-FILEUPLOAD')) || $uniqueId != $this->getId()) { - return; - } - try { if (!Input::hasFile('file_data')) { throw new ApplicationException('File missing from request'); @@ -482,8 +476,7 @@ class FileUpload extends FormWidgetBase $response = Response::make($ex->getMessage(), 400); } - // Override the controller response - $this->controller->setResponse($response); + return $response; } /** diff --git a/modules/backend/formwidgets/fileupload/assets/js/fileupload.js b/modules/backend/formwidgets/fileupload/assets/js/fileupload.js index 091ea6014..20c573035 100644 --- a/modules/backend/formwidgets/fileupload/assets/js/fileupload.js +++ b/modules/backend/formwidgets/fileupload/assets/js/fileupload.js @@ -114,10 +114,6 @@ this.uploaderOptions.previewTemplate = $(this.options.template).html() } - if (this.options.uniqueId) { - this.uploaderOptions.headers['X-OCTOBER-FILEUPLOAD'] = this.options.uniqueId - } - this.uploaderOptions.thumbnailWidth = this.options.thumbnailWidth ? this.options.thumbnailWidth : null @@ -192,6 +188,7 @@ FileUpload.prototype.onUploadSending = function(file, xhr, formData) { this.addExtraFormData(formData) + xhr.setRequestHeader('X-OCTOBER-REQUEST-HANDLER', this.options.uploadHandler) } FileUpload.prototype.onUploadSuccess = function(file, response) { @@ -428,6 +425,7 @@ FileUpload.DEFAULTS = { url: window.location, + uploadHandler: null, configHandler: null, sortHandler: null, uniqueId: null, diff --git a/modules/backend/formwidgets/fileupload/partials/_file_multi.htm b/modules/backend/formwidgets/fileupload/partials/_file_multi.htm index af17fcc4d..0dceb6e35 100644 --- a/modules/backend/formwidgets/fileupload/partials/_file_multi.htm +++ b/modules/backend/formwidgets/fileupload/partials/_file_multi.htm @@ -2,6 +2,7 @@ id="getId() ?>" class="field-fileupload style-file-multi is-sortable is-multi previewMode ? 'is-preview' : '' ?>" data-control="fileupload" + data-upload-handler="getEventHandler('onUpload') ?>" data-template="#getId('template') ?>" data-error-template="#getId('errorTemplate') ?>" data-sort-handler="getEventHandler('onSortAttachments') ?>" diff --git a/modules/backend/formwidgets/fileupload/partials/_file_single.htm b/modules/backend/formwidgets/fileupload/partials/_file_single.htm index 51d033b60..f58ed010b 100644 --- a/modules/backend/formwidgets/fileupload/partials/_file_single.htm +++ b/modules/backend/formwidgets/fileupload/partials/_file_single.htm @@ -2,6 +2,7 @@ id="getId() ?>" class="field-fileupload style-file-single previewMode ? 'is-preview' : '' ?>" data-control="fileupload" + data-upload-handler="getEventHandler('onUpload') ?>" data-template="#getId('template') ?>" data-error-template="#getId('errorTemplate') ?>" data-unique-id="getId() ?>" diff --git a/modules/backend/formwidgets/fileupload/partials/_image_multi.htm b/modules/backend/formwidgets/fileupload/partials/_image_multi.htm index 0747cf6f4..a24b3fbfc 100644 --- a/modules/backend/formwidgets/fileupload/partials/_image_multi.htm +++ b/modules/backend/formwidgets/fileupload/partials/_image_multi.htm @@ -2,6 +2,7 @@ id="getId() ?>" class="field-fileupload style-image-multi is-sortable is-multi previewMode ? 'is-preview' : '' ?>" data-control="fileupload" + data-upload-handler="getEventHandler('onUpload') ?>" data-template="#getId('template') ?>" data-error-template="#getId('errorTemplate') ?>" data-sort-handler="getEventHandler('onSortAttachments') ?>" diff --git a/modules/backend/formwidgets/fileupload/partials/_image_single.htm b/modules/backend/formwidgets/fileupload/partials/_image_single.htm index 7a0629634..8d89e14d7 100644 --- a/modules/backend/formwidgets/fileupload/partials/_image_single.htm +++ b/modules/backend/formwidgets/fileupload/partials/_image_single.htm @@ -2,6 +2,7 @@ id="getId() ?>" class="field-fileupload style-image-single previewMode ? 'is-preview' : '' ?>" data-control="fileupload" + data-upload-handler="getEventHandler('onUpload') ?>" data-template="#getId('template') ?>" data-error-template="#getId('errorTemplate') ?>" data-unique-id="getId() ?>"