Hey everyone. Im having a hard time to import and process a csv file.
I would like to: - upload the file, - let the user do some kind of preprocess, (map columns, and such). - insert records. - dispose the uploaded file. Its a double post i gotta do, one to submit the file, and another for the user to process and commit the previously uploaded file. is it wise to place the file into the session? or is it better to just store the path to the uploaded file to handle it later? This is the first form form1 = SQLFORM.factory( Field("file", "upload", default="", uploadfolder = "applications/myapp/uploads", requires=[IS_NOT_EMPTY("Please select a file." ), IS_UPLOAD_FILENAME(error_message="Only csv files allowed", extension="[csv]", lastdot=True), IS_BINARY(False, "Binary files not allowed")]), ... The problems im having are: if i dont specify an upload folder i get an error. <type 'exceptions.RuntimeError'> you must specify a Field(...,uploadfolder=...) I wonder why the sqlform doesnt know where to store the file, it is no big deal, easy to solve but when the file is uploaded, an empty file gets created as "no_table.file.96474e907bab4168.6d657472696c792e637376.csv", which is ok but its empty. So my question is, do i have to read the request.post_vars.file to save the content to that automatically created empty file? The request.post_vars.file has a reference to, apparently, that file handler, but i cant save any content with that. myfile = request.post_vars.file content = myfile.file.read() content = content.decode("iso-8859-1").encode("utf-8") with myfile.fp as f: f.write(content) Does anyone know resources or care to explain how to upload files without db interaction? The docs doesnt have much about these cases. Thank you very much. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.