Changed post uploads

Post uploads no longer encapsulates file content in base64.
This means dramatic speed up for sending on local networks.
This commit is contained in:
Marcin Kurczewski 2014-11-22 14:32:47 +01:00
parent 77c51d9a8a
commit f2b1e3bedb
3 changed files with 18 additions and 11 deletions

View file

@ -256,10 +256,9 @@ App.Presenters.PostUploadPresenter = function(
} }
function addPostFromFile(file) { function addPostFromFile(file) {
var post = _.extend({}, getDefaultPost(), {fileName: file.name}); var post = _.extend({}, getDefaultPost(), {fileName: file.name, file: file});
fileDropper.readAsDataURL(file, function(content) { fileDropper.readAsDataURL(file, function(content) {
post.content = content;
if (file.type.match('image.*')) { if (file.type.match('image.*')) {
post.thumbnail = content; post.thumbnail = content;
postThumbnailLoaded(post); postThumbnailLoaded(post);
@ -575,17 +574,17 @@ App.Presenters.PostUploadPresenter = function(
var post = posts[0]; var post = posts[0];
var $row = post.$tableRow; var $row = post.$tableRow;
var formData = {}; var formData = new FormData();
if (post.url) { if (post.url) {
formData.url = post.url; formData.append('url', post.url);
} else { } else {
formData.content = post.content; formData.append('content', post.file);
formData.contentFileName = post.fileName; formData.append('contentFileName', post.fileName);
} }
formData.source = post.source; formData.append('source', post.source);
formData.safety = post.safety; formData.append('safety', post.safety);
formData.anonymous = (post.anonymous | 0); formData.append('anonymous', (post.anonymous | 0));
formData.tags = post.tags.join(' '); formData.append('tags', post.tags.join(' '));
if (post.tags.length === 0) { if (post.tags.length === 0) {
showUploadError('No tags set.'); showUploadError('No tags set.');

View file

@ -19,7 +19,7 @@ class UploadFormData implements IValidatable
if ($inputReader !== null) if ($inputReader !== null)
{ {
$this->contentFileName = $inputReader->contentFileName; $this->contentFileName = $inputReader->contentFileName;
$this->content = $inputReader->decodeBase64($inputReader->content); $this->content = $inputReader->readFile('content');
$this->url = $inputReader->url; $this->url = $inputReader->url;
$this->anonymous = $inputReader->anonymous; $this->anonymous = $inputReader->anonymous;
$this->safety = EnumHelper::postSafetyFromString($inputReader->safety); $this->safety = EnumHelper::postSafetyFromString($inputReader->safety);

View file

@ -34,4 +34,12 @@ final class InputReader extends \ArrayObject
$base64string = substr($base64string, $commaPosition + 1); $base64string = substr($base64string, $commaPosition + 1);
return base64_decode($base64string); return base64_decode($base64string);
} }
public function readFile($fileName)
{
if (!isset($_FILES[$fileName]))
return null;
return file_get_contents($_FILES[$fileName]['tmp_name']);
}
} }