webpy上传大文件代码,webpy上传文件代码,webpy上传普通文件的
webpy上传大文件代码,webpy上传文件代码,webpy上传普通文件的
webpy上传普通文件的处理很简单。要上传大文件就需要一点一点的读文件了,否则内存吃不消,文件也就传不上去了。
import webimport timeimport httplib2import httpliburls = ('/upload', 'Upload')class Upload: def GET(self): web.header("Content-Type","text/html; charset=utf-8") return """<html><head></head><body><form method="POST" enctype="multipart/form-data" action=""><input type="file" name="myfile" /><br/><input type="submit" /></form></body></html>""" def POST(self): file_size = web.utils.intget(web.ctx.env.get('CONTENT_LENGTH'), 0) filename = str(time.time()) h2 = httplib.HTTPConnection("192.168.5.11:9500") h2.putrequest("POST", "/api/upload/"+filename) h2.putheader('Content-Type', 'multipart/form-data') h2.putheader('Content-Length', file_size) h2.endheaders() step = 1024*1024*10 while 0<file_size: if file_size - step <= 0: step = file_size data = web.ctx.env['wsgi.input'].read(step) h2.send(data) file_size = file_size - step print '*'*100, filename r2 = h2.getresponse() print r2.status, r2.reason, r2.read() h2.close()if __name__ == "__main__": app = web.application(urls, globals()) app.run()
相关内容
- python里面向shell输出彩色字符串,pythonshell输出,shell里面
- python替换html中的空标签,python替换html标签,html中的空行
- 数独人工算法的python实现,人工算法python,目前只有两个
- python使用os.path和hashlib遍历目录计算所有文件的md5值,
- python过滤字符串中不属于指定集合的字符的类,python字
- python清空linux/unix系统共享内存代码,pythonunix,# -*- cod
- python使用蒙特卡洛方法计算圆周率,python蒙特卡洛,蒙特
- UnicodeDecodeError: 'utf8' codec can't decode
- Python读取浮点数|读文本文件,python点数,[Python]代码im
- python调用摄像头摄像并保存图片,,[Python]代码#!
评论关闭