From e184157684ad923d5d4107b76d6421e6ae28799d Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 22 Jul 2015 13:13:39 +0200 Subject: [avatar] add error handlers for avatar setup add colon to translated string use placeholder in t() Adding a size limitation for avatar upload Unit test for file size Fix typo & display server side error message --- core/avatar/avatarcontroller.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'core') diff --git a/core/avatar/avatarcontroller.php b/core/avatar/avatarcontroller.php index 95baf23f4fa..2c4be827738 100644 --- a/core/avatar/avatarcontroller.php +++ b/core/avatar/avatarcontroller.php @@ -134,6 +134,10 @@ class AvatarController extends Controller { if (isset($path)) { $path = stripslashes($path); $view = new \OC\Files\View('/'.$userId.'/files'); + if ($view->filesize($path) > 20*1024*1024) { + return new DataResponse(['data' => ['message' => $this->l->t('File is too big')]], + Http::STATUS_BAD_REQUEST); + } $fileName = $view->getLocalFile($path); } elseif (!is_null($files)) { if ( @@ -141,6 +145,10 @@ class AvatarController extends Controller { is_uploaded_file($files['tmp_name'][0]) && !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0]) ) { + if ($files['size'][0] > 20*1024*1024) { + return new DataResponse(['data' => ['message' => $this->l->t('File is too big')]], + Http::STATUS_BAD_REQUEST); + } $this->cache->set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200); $view = new \OC\Files\View('/'.$userId.'/cache'); $fileName = $view->getLocalFile('avatar_upload'); -- cgit v1.2.3