Restful api for uploading files

297 views
Skip to first unread message

Sharjeel Ali Shaukat

unread,
Oct 19, 2017, 12:46:47 AM10/19/17
to web2py-users
I want to create a restful api through which i can upload files to web2py application using android or other 3rd party applications. Any useful link or code would be very helpful
Message has been deleted

黄祥

unread,
Oct 19, 2017, 1:13:26 AM10/19/17
to web2py-users
had you read the book :
http://web2py.com/books/default/chapter/29/10/services#Restful-Web-Services

theres an example to do a post

best regards,
stifan

Sharjeel Ali Shaukat

unread,
Oct 19, 2017, 2:03:34 AM10/19/17
to web2py-users
But how can i send a file for uploading

Michele Comitini

unread,
Oct 19, 2017, 6:33:19 AM10/19/17
to web...@googlegroups.com

just send the file in a HTTP POST (multipart encoded) from the client 

Code to do it is similar to this...

@request.restful()
def uploader():
   def POST(*args, **kwargs):

        # if the post is correct only first item is needed
        uploaded_file = kwargs[kwargs.keys()[0]]

        # fake table to use readymade code for upload
        db.define_table('media_content_', Field('bdata', 'upload'), migrate=False)
        filename = db.media_content_.bdata.store(uploaded_file, uploaded_file.filename)

        return dict(message='uploaded to file: {}'.format(filename))

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michele Comitini

unread,
Oct 19, 2017, 6:36:56 AM10/19/17
to web...@googlegroups.com

Sharjeel Ali Shaukat

unread,
Oct 19, 2017, 8:33:10 AM10/19/17
to web2py-users
Thanks its working

Reply all
Reply to author
Forward
0 new messages