On Monday, March 4, 2019 at 11:22:19 AM UTC-8, Sarbjit wrote: > > Hello, > > I am trying to use CURL to upload a file in the 'upload' field using REST > services. But on using the command, some garbage is getting uploaded, even > though it shows as type "file" but I could not download the file (invalid > request) and the URL becomes too lengthy (looks like the file contents are > uploaded) > > Models > > db.define_table('test', Field('date', 'datetime'), > Field('user'), > Field('upload_data','upload')) > > Controllers > > @request.restful() > def api(): > response.view = 'generic.json' > > > def GET(tablename, id): > if not tablename == 'test': > raise HTTP(400) > return dict(record = db.test(id)) > > > def POST(tablename, **fields): > if not tablename == 'test': > raise HTTP(400) > return db.test.validate_and_insert(**fields) > > > return locals() > > CURL syntax > > curl POST -i -F upload_data=@somefile.zip http: > //<servername>:8000/testapp/default/api/test.json > > > Has anyone used the CURL to upload a file (zip file) with web2py? > You're using -F which is for Form data ... is that what you want?
I use --data-binary for a zip file, to an NginX front end, and that works just fine. (-d does not work; my zip file gets truncated at the first 0, and I think there's URL_ENCODING applied before that ). Curl isn't the usual client for my app -- instead, I use libcurl inside my app, which doesn't seem to mind binary. I do set the content-type header, and I provide the size via CURLOPT_POSTFIELDSIZE_LARGE. /dps -- 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.