From d214be301cd975a092631b469c1a436aa05f2e57 Mon Sep 17 00:00:00 2001 From: fatchan Date: Wed, 25 Dec 2019 10:02:00 +1100 Subject: [PATCH] fix multi adding files for some browsers (palemoon now works) --- gulp/res/js/forms.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/gulp/res/js/forms.js b/gulp/res/js/forms.js index b06e9aa6..174e11dc 100644 --- a/gulp/res/js/forms.js +++ b/gulp/res/js/forms.js @@ -61,13 +61,21 @@ class formHandler { } formSubmit(e) { - if (this.files && this.files.length > 0) { - //add files to file input element - const filesToUpload = new DataTransfer(); - for (let i = 0; i < this.files.length; i++) { - filesToUpload.items.add(this.files[i]); + let postData; + if (this.form.getAttribute('enctype') === 'multipart/form-data') { + //remove the file input since some browsers dont supprot formdata.delete() + this.fileInput.remove(); + //make a formdata + postData = new FormData(this.form); + if (this.files && this.files.length > 0) { + //add files to file input element + for (let i = 0; i < this.files.length; i++) { + postData.append('file', this.files[i]); + } } - this.fileInput.files = filesToUpload.files; + } else { + xhr.setRequestHeader('Content-Type', 'application/json'); + postData = formToJSON(this.form); } let isLive = localStorage.getItem('live') == 'true' && socket && socket.connected; if (!this.banned && !isLive) { @@ -152,13 +160,6 @@ class formHandler { } xhr.open(this.form.getAttribute('method'), this.form.getAttribute('action'), true); xhr.setRequestHeader('x-using-xhr', true); - let postData; - if (this.form.getAttribute('enctype') === 'multipart/form-data') { - postData = new FormData(this.form); - } else { - xhr.setRequestHeader('Content-Type', 'application/json'); - postData = formToJSON(this.form); - } xhr.send(postData); }