Search code examples
web2py

Reading file content from uploaded text file


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.


Solution

  • 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.