[英]Upload multiple files with Tornado Web Server and Nginx
我正在使用Python + Tornado + Nginx Web Server开发上传多个文件。 我已如下更改Nginx服务器的属性:
client_body_buffer_size 512K; client_max_body_size 500M;
但是,当发送数量大于3个文件时,它不会转发会议室。 可能会发生什么?
在互联网上,甚至在此处的Stack Overflow上,仅包含单个文件的示例,或者反对创建多个文件的示例
代码如下:
蟒蛇
class UploadHandler(tornado.web.RequestHandler):
def post(self):
try :
t = len(self.request.files)+1
x = 0
n = 'file'
while x <= t:
nn = self.request.files[n][x]
nome_arquivo = nn['filename']
output_file = open("my directory/" + nome_arquivo, 'w')
output_file.write(nn['body'])
x+=1
self.render(
"sucess.html"
)
except IndexError:
self.render(
"sucess.html"
)
HTML
<form enctype="multipart/form-data" method="post" action="/uploads">
<input name="descricao" type="text" /> <br>
<input type="file" name="file" multiple />
<input type="submit" value="Send File(s)">
</form>
朋友,我解决了创建一个索引的问题。 以前没有。
最终决议:
class UploadHandler(tornado.web.RequestHandler):
def post(self):
try :
t = len(self.request.files)
x = 1
indice = 0
n = 'file'
while x <= t:
nn = self.request.files[n][indice]
nome_arquivo = nn['filename']
output_file = open("static/arquivos/" + nome_arquivo, 'w')
output_file.write(nn['body'])
indice+=1
self.render(
"sucess.html"
)
except IndexError:
self.render(
"sucess.html" # this necessary but command while don't achieved implement
) # x+=1 - i don't know why...
# with this resolution, an error will be showed but redirected
# at the same if success
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.