1

在我的 web2py 控制器中,我正在访问文件数据,例如:

vfile = request.post_vars.video.file

但是在上传实际文件数据Content-Length 之前如何检查?上传文件后检查文件大小对我来说不是一个好主意。

注意:我没有使用FORM()帮助程序和数据库,而只是使用原始的常规文件上传。有什么方法可以连接到 web2py 内部来做我需要的事情吗?

4

1 回答 1

0

我认为您必须在浏览器中检测到它并将其传递给 web2py。这就是我在服务器端处理它的方式。我知道您在上传之前询问了尺寸,但我认为这可能会有所帮助。

#insert file in db
image = db.image.file.store(request.vars["files[]"].file, request.vars["files[]"].filename)
id = db.image.insert(file=image,title=request.vars["files[]"].filename)
#get filename in db
record = db.image[id]
#find size
path_list = []
path_list.append(request.folder)
path_list.append('uploads')
path_list.append(record['file'])
print os.path.getsize(os.path.join(*path_list))
于 2012-12-04T11:48:01.837 回答