File (>1000 bytes) upload error/exception: rhodecode/mode/

Issue #856 resolved
Former user created an issue

OS: Windows Server 2008; Python 2.7.5, rhodecode 1.7 (pip installed)

Files (larger than 1000 bytes) could not be uploaded to repository through rhodecode; exception occurs: Exception: Content is of unrecognized type <type 'instance'>

repr(content) is <open file '<fdopen>', mode 'w+b' at 0x.........>

Ironnically, the first file i've tried to upload was production.ini of rhodecode... :-) Of course, could be some configuration issue (newbie user of rhodecode).

Appreciate Your support.

Comments (9)

  1. _lv_

    I think i found the problem. lib/ saves data larger than 1000 bytes to a file. File objects, that are created (by tempfile.TemporaryFile() and others) and returned/passed are dependent on the platform: file like or true file (on POSIX). So, no rhodecode exception until uploaded files are smaller than that, because cgi.FieldStorage returns content of the files as strings (or StringIO) on all platforms. On the other hand, rhodecode/controlers/

                file_obj = r_post.get('upload_file', None)
                if file_obj is not None and hasattr(file_obj, 'filename'):
          "file has filename")
                    filename = file_obj.filename
                    **content = file_obj.file**

    Although content is supposed to reference the file object, but on some platforms (e.g. Windows) it's still of the type 'instance' (file like object, not true file). file_obj.file.file "solves" the problem. Not sure how to resolve this more nicely than:

    content = file_obj.file
    if hasattr(content, '__module__'):
        content = content.file

    Also there could be other places in rhodecode where this platform "file like" bug occurs.

  2. Marcin Kuzminski repo owner

    Ihad a computer crash and lost my windows machines, can you send me what does


    return on windows ?

    I would like to fix that using

    content = file_obj.file
    if isinstance(content, <the_missing_type>):
        content = content.file
  3. Marcin Kuzminski repo owner

    SO i think and from what i read in docs solution like this would work.

    content = file_obj.file
    if hasattr(content, 'file'):
        # non posix systems store real file under file attr
        content = content.file
  4. _lv_

    Excellent. I am confused, why i was checking for the 'module' rather than checking for the 'file' attribute explicitly and clearly.

  5. Marcin Kuzminski repo owner

    this is pushed to stable branch, now so i'm closing this. Thanks for this report !

  6. Log in to comment