1. I do not now. that is outside of web2py control. it is controlled by the browser 2. you can just use
form = SQLFORM.factory(Field('myfile','upload')).process() and then if form.accepted: request.vars.myfile.file.seek(0) data = request.vars.myfile.file.read() On Thursday, 1 December 2016 09:15:25 UTC-6, Kenwyn Pilgrim wrote: > > Massimo > > Thanks. This works. Just 2 follow-up questions. > > > 1. Why does the *Choose File* button continue to say *No file chosen*? > (The form submits though, with no validation errors) > > 2. Can this be done with *SQLFORM.factory *instead of *SQLFORM*? > Meaning that when I set the defaults, including setting the data for field > that represents the upload file, I expect that if I hit the submit button > as my first action, validation should be passed. What happens instead is > that a validation error occurs that makes it seem that a file had not been > had not been chosen. > > (*I noticed the online book (6th edition) does not have any info under > the section Uploading Files with > SQLFORM.factory.(http://www.web2py.com/book/default/chapter/07#Uploading-files-with-SQLFORMfactory > > <http://www.web2py.com/book/default/chapter/07#Uploading-files-with-SQLFORMfactory>)* > ) > > On Friday, November 25, 2016 at 11:17:51 PM UTC-5, Massimo Di Pierro wrote: > >> You are you doing this: >> >> if edit_mode: >> >> id = int(request.args[0]) >> >> q = db.upload_file.id == id >> >> rows = db(q).select() >> >> for row in rows: >> >> for field in row: >> >> if field in db.upload_file.fields: >> >> db.upload_file[field].default = row[field] >> >> >> >> ... >> >> form = SQLFORM.factory(db.upload_file, fields=fields, >> >> submit_button=T('Add to Print Queue') if not >> edit_mode else T('Update Queue'), >> >> upload=URL('download')) >> >> Instead of >> >> button = T('Add to Print Queue') if not edit_mode >> else T('Update Queue') >> form = SQLFORM(db.upload_file, >> request.args(0,cast=int,default=0), >> upload=URL('download'), >> submit_button=button).process() >> >> >> On Monday, 21 November 2016 09:42:54 UTC-6, Kenwyn Pilgrim wrote: >>> >>> I too have this issue with using SQLFORM.factory to edit. >>> >>> My model looks like: >>> >>> db.define_table('upload_file', >>> >>> Field('doc_type', 'reference document_type', required=True, >>> label=T('Type')), >>> >>> Field('pdf_name', 'upload', label=T('PDF Document'), >>> >>> uploadfolder=os.path.join(request.folder, 'uploads', >>> 'user_data')),...) >>> >>> >>> my controller looks like: >>> >>> ... >>> >>> >>> edit_mode = len(request.args) > 0 >>> >>> if edit_mode: >>> >>> id = int(request.args[0]) >>> >>> q = db.upload_file.id == id >>> >>> rows = db(q).select() >>> >>> for row in rows: >>> >>> for field in row: >>> >>> if field in db.upload_file.fields: >>> >>> db.upload_file[field].default = row[field] >>> >>> >>> >>> ... >>> >>> form = SQLFORM.factory(db.upload_file, fields=fields, >>> >>> submit_button=T('Add to Print Queue') if not >>> edit_mode else T('Update Queue'), >>> >>> upload=URL('download')) >>> >>> ... >>> >>> >>> If I am in edit mode and hit the "Update Queue" button, I get the >>> validation error "Please select a file", even though I have prepopulated >>> the defaults. >>> >>> I have to click the "Choose File" button to select a file *again, *then it >>> works. >>> >>> >>> Please help. >>> >>> Thanks. >>> >>> >>> On Saturday, April 6, 2013 at 11:22:32 AM UTC-5, Massimo Di Pierro wrote: >>>> >>>> what are the models? >>>> >>>> On Tuesday, 2 April 2013 12:19:12 UTC-5, Ramos wrote: >>>>> >>>>> Back to business after almost 2 months i try again to use >>>>> sqlform.factory to create and edit documents >>>>> My problem was to generate the link >>>>> i rearranged my code as follows >>>>> >>>>> >>>>> #if edit a document >>>>> if request.args(0): >>>>> >>>>> row=db((db.trabalhador.id==request.args(0))).select().first() >>>>> >>>>> empresa=row.empresa >>>>> >>>>> foto=row['foto'] or None >>>>> #print foto >>>>> if row: >>>>> for field in row: >>>>> >>>>> if field in db.trabalhador.fields: >>>>> #POPULATE FIELDS with record to edit >>>>> db.trabalhador[field].default=row[field] >>>>> >>>>> form=SQLFORM.factory(db.trabalhador,db.t_docs, >>>>> submit_button="Gravar", >>>>> >>>>> fields=['nome','bi','ncart','ncartval','rfid','apt_medica','apt_medicaval','val_formacao','f_doc'], >>>>> table_name='trabalhador', >>>>> upload=URL('download') >>>>> ) >>>>> >>>>> I see my record and upload fields with [file] link. The [file] link >>>>> downloads my uploaded file. >>>>> My upload fields have required= true in db.py!!! >>>>> I do nothing and just press save >>>>> >>>>> I get the error saying that i have to select a file to my upload >>>>> field. >>>>> >>>>> I´m stuck >>>>> >>>>> Help please..... >>>>> >>>> -- 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.