Tornado 上传文件及存储
2013-05-29 18:32
148 查看
http://blog.csdn.net/zhoucy163/article/details/8777839
上传文件
[python] view
plaincopy
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render('/home/zz/index.html')
class UploadHandler(tornado.web.RequestHandler):
def post(self):
if self.request.files:
myfile = self.request.files['myfile'][0]
fin = open("/home/zz/in.jpg","w")
print "success to open file"
fin.write(myfile["body"])
fin.close()
application=tornado.web.Application([(r'/',MainHandler),(r'/upload', UploadHandler) ]
)
if __name__=='__main__':
application.listen(2033)
tornado.ioloop.IOLoop.instance().start()
[html] view
plaincopy
<html>
<body>
<form action="/upload" enctype="multipart/form-data" method="post">
<input name="myfile" type="file">
<input type="submit" value="Submit">
</form>
</body></html>
其中python中UploadHandler中的“/upload”一定要出现在index.html中的表单的action属性中,必须一致。
action和methhod 都是对当前form的提交进行设置
action="提交到地址以及相关参数"
method="设置提交方式"
上传文件
[python] view
plaincopy
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render('/home/zz/index.html')
class UploadHandler(tornado.web.RequestHandler):
def post(self):
if self.request.files:
myfile = self.request.files['myfile'][0]
fin = open("/home/zz/in.jpg","w")
print "success to open file"
fin.write(myfile["body"])
fin.close()
application=tornado.web.Application([(r'/',MainHandler),(r'/upload', UploadHandler) ]
)
if __name__=='__main__':
application.listen(2033)
tornado.ioloop.IOLoop.instance().start()
[html] view
plaincopy
<html>
<body>
<form action="/upload" enctype="multipart/form-data" method="post">
<input name="myfile" type="file">
<input type="submit" value="Submit">
</form>
</body></html>
其中python中UploadHandler中的“/upload”一定要出现在index.html中的表单的action属性中,必须一致。
action和methhod 都是对当前form的提交进行设置
action="提交到地址以及相关参数"
method="设置提交方式"
相关文章推荐
- 关于tornado文件上传与存储
- Tornado 上传文件及存储
- node+express用multer上传图片或者文件到服务器及用日期命名图片存储的文件夹
- tornado 来实现简单的文件上传功能
- 百度——个人云存储pcs——Android使用百度云盘(2)——创建文件夹和上传文件
- DiskFileItemFactory 文件上传存储
- laravel5.4文件存储实战利用ajax上传图片
- 最代码的上传的代码文件存储什么地方呢?
- ASP.Net 5 上传文件通过虚拟路径存储
- 使用Mongodb存储上传物理文件并进行SQUID加速(基于aspx页面)
- php上传文件并存储到mysql数据库的方法
- linux 软连接方式实现上传文件存储目录的无缝迁移
- 基于腾讯COS对象存储SDK使用Python编写的文件上传工具第二版
- 使用Mongodb存储上传物理文件并进行SQUID加速(基于aspx页面)
- Python tornado上传文件
- fileupload上传文件存储到oracle Blob字段中
- jquery.uploadify-3.1+servlet实现多文件的上传和下载文件存储到BLOB中
- 将通过<input type="file">上传的txt文件存储在localStorage,提取并构建File对象
- 第二百七十三节,Tornado框架-文件上传
- WordPress在SAE环境上传文件至storage存储