simple file uploader to database as a plugin

34 views
Skip to first unread message

Vic Ding

unread,
Jun 14, 2016, 2:50:00 PM6/14/16
to web2py-users

Hi all,
I know it's 2 things in one post: how to make a file uploader as a plugin?
It should upload a file store it in the database and keep a record of the table and record to which it belong to (associate the uploaded file with a record in another table). 

model is plugin_upload_file.py
db.define_table('plugin_upload_file',
                auth
.signature,
               
Field('title', 'string'),
               
Field('description', 'text'),
               
Field('upload_file', 'upload'),
               
Field('table_name', 'string'),
               
Field('record_id', 'integer'),
               
format = '%(title)s'
)


I have controller/plugin_upload_file.py
def index():

    table_name
= request.args(0)
    record_id
= request.args(1, cast=long)

   
## pre-fill the table_name and record_id
    db.plugin_upload_file.table_name.default = table_name
    db
.plugin_upload_file.record_id.default = record_id

    plugin_upload_file_form = SQLFORM(db.plugin_upload_file).process()
   
if plugin_upload_file_form.accepted:
        response
.flash=T('File saved')
        redirect
(URL('index', args=(table_name, record_id)))
   
else:
        response
.flash=T('Error')

   
return locals()

Finally the view in view/plugin_upload_file/index.html
{{=plugin_upload_file_form}}

It works when I directly access the index page, however when I LOAD it to other pages it stops working. No ticket, no error. 
{{=LOAD('plugin_upload_file', 'index', args=('item', item_id), user_signature=True)}}


Any idea?

Thanks
Vic

Manuele Pesenti

unread,
Jun 17, 2016, 8:52:18 AM6/17/16
to web...@googlegroups.com
Il 14/06/16 20:50, Vic Ding ha scritto:
It works when I directly access the index page, however when I LOAD it to other pages it stops working. No ticket, no error. 
{{=LOAD('plugin_upload_file', 'index', args=('item', item_id), user_signature=True)}}


Any idea?

maybe it could help: http://www.web2py.com/books/default/chapter/29/12/components-and-plugins#Ajax-post-does-not-support-multipart-forms

From a vary fast reading I think it's just about a case like yours...

    M.

Reply all
Reply to author
Forward
0 new messages