Reading file content from uploaded text file

2019-05-31 03:00发布

问题:

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.

回答1:

You can do something like:

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.



标签: web2py