i use postman(http://www.getpostman.com/) for test restful api and works 
grate...

El lunes, 5 de mayo de 2014 11:49:50 UTC-5, iw3...@gmail.com escribió:
>
> Hi!
>
> I have a SQLFORM with some filelds and an image (like example here: 
> http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM).
>
> I have to populate the database using a python script. So I made a generic 
> restful api:
>
> @request.restful()
> def api():
>     response.view = 'generic.'+request.extension
>     def GET(*args,**vars):
>         patterns = [':auto[products]',
>                     '/products/code/{products.code}',
>                     '/products/code/{products.code}/:field',
>                     '/products/image_filename/{products.image_filename}',
>                     
> '/products/image_filename/{products.image_filename}/:field',
>                    ]
>         parser = db.parse_as_rest(patterns,args,vars)
>         if parser.status == 200:
>             return dict(content=parser.response)
>         else:
>             raise HTTP(parser.status,parser.error)
>     def POST(table_name,**vars):
>         return db[table_name].validate_and_insert(**vars)
>     def PUT(table_name,record_id,**vars):
>         return db(db[table_name]._id==record_id).validate_and_update(**
> vars)
>     def DELETE(table_name,record_id):
>         return db(db[table_name]._id==record_id).delete()
>     return dict(GET=GET, POST=POST, PUT=PUT, DELETE=DELETE)
>
> On python script  I use requests.post and genercs fields are ok.
> I used sintax from here ( 
> http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
>  
> ).
> This upload generally work but I have a big problem:
> uploading file from browser I find on DB the encoded name of file, and dhe 
> file on filesystem.
> Uploading from restful I find on db, instead of encoded file name, this:
>
> 'FieldStorage(''image'', ''test_image.jpg'', ''...binary data of image'')'
>
> What's the correct way to upload a file using restful api?
>

-- 
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.

Reply via email to