从上传的文本文件中读取文件内容

问题描述:

我在uploads文件夹中有一个上传的文件,我需要在控制器中读取它的内容以进一步处理它.我对 web2py 有非常基本的了解,但不知道该怎么做.

I have an uploaded file in uploads folder and i need to read the contents from it in the controller for processing it further. I have very basic knowledge of web2py and couldn't understand how to do it.

您可以执行以下操作:

import os
filename = db.mytable(record_id).myfile
content = open(os.path.join(request.folder, 'uploads', filename), 'rb').read()

更新:这里是一种更简单的方法.

UPDATE: Here is a somewhat simpler approach.