How to get the size (bytes) of an attachment

I want to get the size in byte of the attached pdf files

Class Attachment (), has a function get_size() and data_size(). However it does not return the value.

data_size = fields.Function(fields.Integer('Data size', states={
                'invisible': Eval('type') != 'data',
                }, depends=['type']), 'get_size')

def get_size(self, name):
        with Transaction().set_context({
                    '%s.%s' % (self.__name__, name): 'size',
            record = self.__class__(

Normally the field data_size should contain the size of the attachment.
But if you are using a custom filestore, it may not implement the size.