diff --git a/include/api.tickets.php b/include/api.tickets.php
index feca779c56927422490373136e8feb48d0bbd8d1..7cebb81be017d946b53e01d1be46a0d48b038905 100644
--- a/include/api.tickets.php
+++ b/include/api.tickets.php
@@ -69,6 +69,15 @@ class TicketApiController extends ApiController {
                     if(!($attachment['data'] = base64_decode($attachment['data'], true)))
                         $attachment['error'] = sprintf('%s: Poorly encoded base64 data', Format::htmlchars($attachment['name']));
                 }
+                if (!$attachment['error']
+                        && ($size = $ost->getConfig()->getMaxFileSize())
+                        && ($fsize = $attachment['size'] ?: strlen($attachment['data']))
+                        && $fsize > $size) {
+                    $attachment['error'] = sprintf('File %s (%s) is too big. Maximum of %s allowed',
+                            Format::htmlchars($attachment['name']),
+                            Format::file_size($fsize),
+                            Format::file_size($size));
+                }
             }
             unset($attachment);
         }