diff --git a/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js b/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js index 62d86433460..21389d17c76 100644 --- a/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js +++ b/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js @@ -24,6 +24,7 @@ import { cacheShortUploadUrl } from "pretty-text/upload-short-url"; import { inject as service } from "@ember/service"; import { run } from "@ember/runloop"; import escapeRegExp from "discourse-common/utils/escape-regexp"; +import { updateCsrfToken } from "discourse/lib/ajax"; // Note: This mixin is used _in addition_ to the ComposerUpload mixin // on the composer-editor component. It overrides some, but not all, @@ -39,6 +40,8 @@ import escapeRegExp from "discourse-common/utils/escape-regexp"; // export default Mixin.create(ExtendableUploader, UppyS3Multipart, { dialog: service(), + session: service(), + uploadRootPath: "/uploads", uploadTargetBound: false, useUploadPlaceholders: true, @@ -596,8 +599,13 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, { }, @bind - _addFiles(files, opts = {}) { + async _addFiles(files, opts = {}) { + if (!this.session.csrfToken) { + await updateCsrfToken(); + } + files = Array.isArray(files) ? files : [files]; + try { this._uppyInstance.addFiles( files.map((file) => { diff --git a/app/assets/javascripts/discourse/app/mixins/uppy-upload.js b/app/assets/javascripts/discourse/app/mixins/uppy-upload.js index 60369704faf..45fab75dc3b 100644 --- a/app/assets/javascripts/discourse/app/mixins/uppy-upload.js +++ b/app/assets/javascripts/discourse/app/mixins/uppy-upload.js @@ -3,7 +3,7 @@ import { run } from "@ember/runloop"; import ExtendableUploader from "discourse/mixins/extendable-uploader"; import { or } from "@ember/object/computed"; import EmberObject from "@ember/object"; -import { ajax } from "discourse/lib/ajax"; +import { ajax, updateCsrfToken } from "discourse/lib/ajax"; import { bindFileInputChangeListener, displayErrorForUpload, @@ -429,8 +429,13 @@ export default Mixin.create(UppyS3Multipart, ExtendableUploader, { }, @bind - _addFiles(files, opts = {}) { + async _addFiles(files, opts = {}) { + if (!this.session.csrfToken) { + await updateCsrfToken(); + } + files = Array.isArray(files) ? files : [files]; + try { this._uppyInstance.addFiles( files.map((file) => {