Hi Ferran,
In data lunedì 6 maggio 2013 12:54:32, Ferran Jorba ha scritto:
> > In data venerdì 3 maggio 2013 14:23:23, Ferran Jorba ha scritto:
> >> it turns out that I have several mod_python scripts to handle local
> >> file uploading needs. After many hours of digging in, I have
> >> confirmed that file uploading is not implemented under the simplified
> >> Invenio SimulatedModPythonRequest. Is that right?
> >
> > yep, it is :-)
>
> Sorry, I don't understand if you confirm that it is implemented in
> your SimulatedModPythonRequest or that it is not implemented and I
> should use ckeditor.
Yes, It is fully implemented in SimulatedModPythonRequest (without that we
wouldn’t have been able to drop dependency over mod_python and migrate to
mod_wsgi).
> > Simply if you set up an HTML form that has a file element, say called
> > “file”, then in req does everything (as in mod_python), in req.form
> > (which behaves like a dictionary), you will find the “file” key that
> > has special properties (e.g. you can call req[‘form’].filename to
> > retrieve the intended filename, and you can call req[‘form’].file to
> > obtain an open stream to the read the content of the file.
>
> I've tried both a plain SimulatedModPythonRequest form and a ckeditor
> form, and both as req['form'].filename (as you wrote) and
> req.form['filename'] (like the other fields), and none of them works:
>>
> Plain SimulatedModPythonRequest:
>
> filename = req['form'].filename
> TypeError: 'SimulatedModPythonRequest' object is unsubscriptable
> (<string>:162:upload)
>
> filename = req.form['filename']
> KeyError: 'filename' (webinterface_handler_wsgi_utils.py:680:__getitem__)
>
> Using ckeditor:
>
> filename = req.form['filename']
> TypeError: 'NoneType' object is not iterable
> (webinterface_handler_wsgi.py:603:mp_legacy_publisher)
>
>
> filename = req['form'].filename
> TypeError: 'NoneType' object is not iterable
> (webinterface_handler_wsgi.py:603:mp_legacy_publisher)
> Would you mind to clarify me which framework should I use, and confirm
> the right syntax (req['form'].filename or req.form['filename']), as all
> my tests have been unsuccessful? Or point me to an example, because, as
> much as I tried, I wasn't able to find a simple one?
:-)
If your HTML form has field called e.g. “foo” of type “file” you will then be
able to do:
req.form[‘foo’].filename to obtain the name.
req.form[‘foo’].file to obtain the open file object, so e.g. you can use
req.form['foo'].file.read() to read its whole content ;-) (but be careful in
this case because if the file that was sent is too big it would fill-up all
the memory :-) ).
Cheers!
Sam
--
Samuele Kaplun
Invenio Developer ** <http://invenio-software.org/>
INSPIRE Service Manager ** <http://inspirehep.net/>