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) {
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.');

View file

@ -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);

View file

@ -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']);
}
}