Question

I am using a sqlform to upload a video file and want to encoding the video file while uploading. But I noticed that the upload file is not saved to uploads directory utill it is completely uploaded. Is there a temporary file and how can I access it ?Thanks.

Was it helpful?

Solution

I'm not sure how you might be able to process the file while it is uploading (i.e., process the bytes as they are received by the server), but if you can wait until the file is fully uploaded, you can access the uploaded file as a Python cgi.FieldStorage object:

def upload():
    if request.vars.myfile:
        video = encode_video(request.vars.myfile.file)
        [do something with video]
    form = SQLFORM.factory(Field('myfile', 'upload',
        uploadfolder='/path/to/upload')).process()
    return dict(form=form)

Upon upload, request.vars.myfile will be a cgi.FieldStorage object, and the open file object will be in request.vars.myfile.file. Note, if the encoding takes a while, you might want to pass it off to a task queue rather than handle it in the controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top