开发者

I can't upload a file with CGIHTTPServer

I'm using the CGIHTTPServer to implement a simple cgi server. I'm trying to upload a file by a form with the post method and the multipart/form-data enctype but I have problems when I recover the value of the fields in the cgi script.

When the script catch the form fields, the value of the file is a MiniFieldStorage with two fields only (key and file name), and I can't recover the content of the file. As the API doc shows, this content is in value field of a StorageField 开发者_JS百科but in the MiniFieldStorage this field isn't exits.

¿How can I recover a StorageField with the content of the file instead a MiniStorageField? ¿There are other method to upload a file using CGIHTTPServer?

Thanks a lot


Please provide some code example. Guessing from the text, you should look into the cgi module. Follow the examples, specially the cgi.test() function.

cgi — Common Gateway Interface support

Support module for Common Gateway Interface (CGI) scripts.

This module defines a number of utilities for use by CGI scripts written in Python.

Quoting the FieldStorage description (using the cgi module):

To get at submitted form data, it’s best to use the FieldStorage class. The other classes defined in this module are provided mostly for backward compatibility. Instantiate it exactly once, without arguments. This reads the form contents from standard input or the environment (depending on the value of various environment variables set according to the CGI standard). Since it may consume standard input, it should be instantiated only once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜