python upload - tmp/FILES 在哪里?
我正在从 cgi 运行 python 2.4,并尝试使用 python api 上传到云服务。 在 php 中,$_FILE 数组包含一个“tmp”元素,该元素是文件所在的位置,直到您将其放置在您想要的位置为止。 python 中的等价物是什么?
如果我这样做,
fileitem = form['file']
fileitem.filename
是文件的名称
(如果我打印 fileitem),则数组仅包含文件名和看起来是文件本身的内容。
我正在尝试传输内容,并且在使用 php api 时需要 tmp 位置。
I'm running python 2.4 from cgi and I'm trying to upload to a cloud service using a python api. In php, the $_FILE array contains a "tmp" element which is where the file lives until you place it where you want it. What's the equivalent in python?
if I do this
fileitem = form['file']
fileitem.filename
is the name of the file
if i print fileitem, the array simply contains the file name and what looks to be the file itself.
I am trying to stream things and it requires the tmp location when using the php api.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该文件是一个真实的文件,但
cgi.FieldStorage
在创建该文件后立即取消了它的链接,这样它仅在您保持打开状态时才存在,并且在该文件上不再具有真实路径文件系统。但是,您可以更改此设置...
您可以扩展
cgi.FieldStorage
并替换make_file
方法以将文件放置在您想要的任何位置:您还必须记住
FieldStorage
对象仅在收到超过 1000B 时才创建真实文件(否则它是cStringIO.StringIO
)编辑:
cgi
模块实际上使用tempfile
模块生成文件,因此如果您需要大量详细信息,请检查一下。The file is a real file, but the
cgi.FieldStorage
unlinked it as soon as it was created so that it would exist only as long as you keep it open, and no longer has a real path on the file system.You can, however, change this...
You can extend the
cgi.FieldStorage
and replace themake_file
method to place the file wherever you want:You must also keep in mind that the
FieldStorage
object only creates a real file if it recieves more than 1000B (otherwise it is acStringIO.StringIO
)EDIT: The
cgi
module actually makes the file with thetempfile
module, so check that out if you want lots of gooey details.这是从我的网站获取的代码片段:
希望这有帮助。
Here's a code snippet taken from my site:
Hope this helps.