Ticket #13531: django-find-size-without-name.diff

File django-find-size-without-name.diff, 1006 bytes (added by douglasbagnall, 14 years ago)
  • django/core/files/base.py

     
    3535    def _get_size(self):
    3636        if not hasattr(self, '_size'):
    3737            if hasattr(self.file, 'size'):
    38                 self._size = self.file.size
    39             elif os.path.exists(self.file.name):
     38                self._size = self.file.size           
     39            elif hasattr(self.file, 'name') and os.path.exists(self.file.name):
    4040                self._size = os.path.getsize(self.file.name)
    4141            else:
    42                 raise AttributeError("Unable to determine the file's size.")
     42                try:
     43                    self.file.seek(0, 2)
     44                    self._size = self.file.tell()
     45                except IOError:
     46                    raise AttributeError("Unable to determine the file's size.")
    4347        return self._size
    4448
    4549    def _set_size(self, size):
Back to Top