简体   繁体   English

我无法使用CGIHTTPServer上传文件

[英]I can't upload a file with CGIHTTPServer

I'm using the CGIHTTPServer to implement a simple cgi server. 我正在使用CGIHTTPServer来实现一个简单的cgi服务器。 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. 我正在尝试使用post方法和multipart / form-data编码类型通过表单上传文件,但是在恢复cgi脚本中的字段值时遇到问题。

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. 当脚本捕获表单字段时,文件的值为MiniFieldStorage,其中只有两个字段(键和文件名),我无法恢复文件的内容。 As the API doc shows, this content is in value field of a StorageField but in the MiniFieldStorage this field isn't exits. 如API文档所示,此内容位于StorageField的value字段中,但在MiniFieldStorage中,此字段不会退出。

¿How can I recover a StorageField with the content of the file instead a MiniStorageField? ¿如何恢复带有文件内容的StorageField而不是MiniStorageField? ¿There are other method to upload a file using CGIHTTPServer? ¿还有其他使用CGIHTTPServer上传文件的方法吗?

Thanks a lot 非常感谢

Please provide some code example. 请提供一些代码示例。 Guessing from the text, you should look into the cgi module . 根据文字进行猜测,您应该查看cgi模块 Follow the examples, specially the cgi.test() function. 遵循示例,尤其是cgi.test()函数。

cgi — Common Gateway Interface support cgi通用网关接口支持

Support module for Common Gateway Interface (CGI) scripts. 通用网关接口(CGI)脚本的支持模块。

This module defines a number of utilities for use by CGI scripts written in Python. 该模块定义了许多实用程序,可用于以Python编写的CGI脚本。

Quoting the FieldStorage description (using the cgi module): 引用FieldStorage描述 (使用cgi模块):

To get at submitted form data, it's best to use the FieldStorage class. 要获取提交的表单数据,最好使用FieldStorage类。 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). 这将从标准输入或环境中读取表单内容 (取决于根据CGI标准设置的各种环境变量的值)。 Since it may consume standard input, it should be instantiated only once. 由于它可能消耗标准输入,因此只能实例化一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM