[issue9968] Let cgi.FieldStorage have named uploaded file

phep report at bugs.python.org
Tue Jul 26 22:56:48 CEST 2011


phep <patrice.pillot at teletopie.net> added the comment:

Hi,

This was test code :-/. It was not under revision control and 
unfortunately, as I feared then, it turned out I had to stop
working shortly after my last message on the low-priority
project that made me report this issue .

Yet, I have a tarball of a presumably-not-so-different version
of the code and I experimented with it this afternoon. Actually,
I could not reproduce the problem I reported in msg117933. So, 
basically, the idea of replacing tempfile.TemporaryFile() by
tempfile.NamedTemporaryFile() seems to really be valid, whatever
the position of the form field.

Yet I found another problem, quite reproducible that one, that
seems to have some fame on Google. Due to the way cgi.__write()
is written, contents of uploaded files with small sizes will be
stored as StringIO. Consequently, sort-of calling
fieldstorage['filenamefield'].file.name will fail. De facto,
this may actually be the error I alluded to in msg117933 - I 
honestly cannot remember what I observed then: « c'est
l'âge...».

So the patch should then be one line longer: we would need
to change __write() to add a check on the value of 'filename' :
-           if self.__file.tell() + len(line) > 1000:
+           if self.filename or self.__file.tell() + len(line) > 1000:

This way, long textareas (for example), keep being stored on
disk if this has any importance.

There is yet one question I cannot answer: where does the 1ko 
barrier come from? Was it only chosen out of performance
considerations, or was there another reason? As I am quite new 
to Python I fear I may miss something obvious.

HTH

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9968>
_______________________________________


More information about the Python-bugs-list mailing list