]> BookStack Code Mirror - bookstack/blobdiff - resources/js/components/dropzone.js
Update docker-compose.yml
[bookstack] / resources / js / components / dropzone.js
index 2b8b35081188f8754a744b5fd412a86076224670..93e93a251c7a6e1eaedfc3c5bdf38521cbda9a8b 100644 (file)
@@ -15,6 +15,7 @@ export class Dropzone extends Component {
         this.isActive = true;
 
         this.url = this.$opts.url;
+        this.method = (this.$opts.method || 'post').toUpperCase();
         this.successMessage = this.$opts.successMessage;
         this.errorMessage = this.$opts.errorMessage;
         this.uploadLimitMb = Number(this.$opts.uploadLimit);
@@ -167,6 +168,9 @@ export class Dropzone extends Component {
     startXhrForUpload(upload) {
         const formData = new FormData();
         formData.append('file', upload.file, upload.file.name);
+        if (this.method !== 'POST') {
+            formData.append('_method', this.method);
+        }
         const component = this;
 
         const req = window.$http.createXMLHttpRequest('POST', this.url, {
@@ -177,10 +181,7 @@ export class Dropzone extends Component {
                 if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
                     upload.markSuccess(component.successMessage);
                 } else if (this.readyState === XMLHttpRequest.DONE && this.status >= 400) {
-                    const content = this.responseText;
-                    const data = content.startsWith('{') ? JSON.parse(content) : {message: content};
-                    const message = data?.message || data?.error || content;
-                    upload.markError(message);
+                    upload.markError(window.$http.formatErrorResponseText(this.responseText));
                 }
             },
         });