diff --git a/app/config/storage/logos.php b/app/config/storage/logos.php index 3170762dca..39d8a40fa6 100644 --- a/app/config/storage/logos.php +++ b/app/config/storage/logos.php @@ -2,6 +2,7 @@ return [ // Based on this list @see http://stackoverflow.com/a/4212908/2299554 'default' => __DIR__.'/logos/none.png', + 'default_image' => __DIR__.'/logos/image.png', // Video Files 'video/mp4' => __DIR__.'/logos/video.png', diff --git a/app/config/storage/logos/image.png b/app/config/storage/logos/image.png new file mode 100644 index 0000000000..c046b4e603 Binary files /dev/null and b/app/config/storage/logos/image.png differ diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index ff0ae96aa7..a299013547 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -915,8 +915,14 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') $cipher = $file->getAttribute('openSSLCipher'); $mime = $file->getAttribute('mimeType'); - if (!\in_array($mime, $inputs)) { - $path = (\array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default']; + if (!\in_array($mime, $inputs) || $file->getAttribute('sizeActual') > APP_LIMIT_PREVIEW) { + if(!\in_array($mime, $inputs)) { + $path = (\array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default']; + } else { + // it was an image but the file size exceeded the limit + $path = $fileLogos['default_image']; + } + $algorithm = null; $cipher = null; $background = (empty($background)) ? 'eceff1' : $background; @@ -924,6 +930,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') $key = \md5($path . $width . $height . $gravity . $quality . $borderWidth . $borderColor . $borderRadius . $opacity . $rotation . $background . $output); } + $compressor = new GZIP(); if (!$deviceFiles->exists($path)) { diff --git a/app/init.php b/app/init.php index 1b4b0f18bf..92ae380fb2 100644 --- a/app/init.php +++ b/app/init.php @@ -67,6 +67,7 @@ const APP_LIMIT_USERS = 10000; const APP_LIMIT_ANTIVIRUS = 20000000; //20MB const APP_LIMIT_ENCRYPTION = 20000000; //20MB const APP_LIMIT_COMPRESSION = 20000000; //20MB +const APP_LIMIT_PREVIEW = 10000000; //10MB file size limit for preview endpoint const APP_CACHE_BUSTER = 201; const APP_VERSION_STABLE = '0.13.0'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; diff --git a/docs/references/storage/get-file-preview.md b/docs/references/storage/get-file-preview.md index a6f4a6186d..3876fd02ed 100644 --- a/docs/references/storage/get-file-preview.md +++ b/docs/references/storage/get-file-preview.md @@ -1 +1 @@ -Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. \ No newline at end of file +Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. Preview is supported only for image files smaller than 10MB. \ No newline at end of file