This

    form=SQLFORM(db.fileobject)
    if request.vars.upload:
        form.vars.filename = request.vars.upload.filename
    if form.process().accepted: ...

should work. Please open a ticket.


On Friday, 28 December 2012 03:15:52 UTC-6, Joe Barnhart wrote:
>
> I'm not sure why this is difficult, but I see many posts about this when I 
> search, yet none exactly work for me.  This seems like it should be easy 
> but is surprisingly difficult in web2py.
>
> I want to keep a table of uploaded files with the uploads in a "blob" 
> field and the names in clear text in a "filename" field.  Like this model:
>
> db.define_table("fileobject",
>     Field("filename","string",length=50,readable=False,writable=False),
>     Field("upload","upload",uploadfield="object_data"),
>     Field("object_type","string",length=20,readable=False,writable=False),
>     Field("object_data","blob"),
>     Field("owner","reference auth_user",default=auth.user_id,readable=
> False,writable=False),
>     Field("saved","datetime",default=datetime.now(),readable=False,
> writable=False),
>     Field("state","string",length=16,readable=False,writable=False),
>     migrate=settings.migrate)
>
> Reading the relevant posts and the online book lead me to believe the way 
> is with a controller like this one:
>
> def index():
>     form=SQLFORM(db.fileobject)
>     if request.vars.upload:
>         form.vars.filename = request.vars.upload.filename
>     if form.process().accepted:
>         response.flash = 'form accepted'
>     elif form.errors:
>         response.flash = 'form has errors'
>     return dict(form=form)
>
> And yet this controller does not work.  The blob is filled in but the 
> filename is ignored and shows in the table as "None".  In fact, form.vars 
> is an empty collection and placing form.vars.filename in it does not 
> produce an error, but it is ignored by the form processing.  In addition to 
> the filename, I'd like to add the information about the object type etc. at 
> the same point in the process, i.e. after the file has been chosen but 
> before it has been loaded into the database.
>
> I've been trying to scan through the code (I'm using 2.3.2 source) to 
> answer my own questions about the upload field but it's just taking too 
> much time.  The upload field is one of those parts of web2py that you 
> either love or... uh... don't.  To me it seems designed for a very specific 
> use model.  If my use model deviates too much then using "upload" is like 
> pounding square pegs into round holes.  I'm tired of pounding.  Someone 
> show me how to whittle off the corners of my square peg!
>
> (You would think this would be an easy task, yet from the number of posts 
> on this exact topic I know I'm in the company of a large number of others.)
>
>
>

-- 



Reply via email to