diff --git a/public_html/js/Presenters/PostUploadPresenter.js b/public_html/js/Presenters/PostUploadPresenter.js index 5b0d93a0..86756b0a 100644 --- a/public_html/js/Presenters/PostUploadPresenter.js +++ b/public_html/js/Presenters/PostUploadPresenter.js @@ -256,10 +256,9 @@ App.Presenters.PostUploadPresenter = function( } function addPostFromFile(file) { - var post = _.extend({}, getDefaultPost(), {fileName: file.name}); + var post = _.extend({}, getDefaultPost(), {fileName: file.name, file: file}); fileDropper.readAsDataURL(file, function(content) { - post.content = content; if (file.type.match('image.*')) { post.thumbnail = content; postThumbnailLoaded(post); @@ -575,17 +574,17 @@ App.Presenters.PostUploadPresenter = function( var post = posts[0]; var $row = post.$tableRow; - var formData = {}; + var formData = new FormData(); if (post.url) { - formData.url = post.url; + formData.append('url', post.url); } else { - formData.content = post.content; - formData.contentFileName = post.fileName; + formData.append('content', post.file); + formData.append('contentFileName', post.fileName); } - formData.source = post.source; - formData.safety = post.safety; - formData.anonymous = (post.anonymous | 0); - formData.tags = post.tags.join(' '); + formData.append('source', post.source); + formData.append('safety', post.safety); + formData.append('anonymous', (post.anonymous | 0)); + formData.append('tags', post.tags.join(' ')); if (post.tags.length === 0) { showUploadError('No tags set.'); diff --git a/src/FormData/UploadFormData.php b/src/FormData/UploadFormData.php index b5500fcb..4b9f4987 100644 --- a/src/FormData/UploadFormData.php +++ b/src/FormData/UploadFormData.php @@ -19,7 +19,7 @@ class UploadFormData implements IValidatable if ($inputReader !== null) { $this->contentFileName = $inputReader->contentFileName; - $this->content = $inputReader->decodeBase64($inputReader->content); + $this->content = $inputReader->readFile('content'); $this->url = $inputReader->url; $this->anonymous = $inputReader->anonymous; $this->safety = EnumHelper::postSafetyFromString($inputReader->safety); diff --git a/src/Helpers/InputReader.php b/src/Helpers/InputReader.php index b366a8aa..0a3564da 100644 --- a/src/Helpers/InputReader.php +++ b/src/Helpers/InputReader.php @@ -34,4 +34,12 @@ final class InputReader extends \ArrayObject $base64string = substr($base64string, $commaPosition + 1); return base64_decode($base64string); } + + public function readFile($fileName) + { + if (!isset($_FILES[$fileName])) + return null; + + return file_get_contents($_FILES[$fileName]['tmp_name']); + } }