On Monday, March 4, 2019 at 2:11:28 PM UTC-8, Sarbjit wrote:
>
> In my actual app, I have multiple fields which needs to be populated along
> with file upload. I have never used CURL before, so I don't know how to
> handle this case. I can try with --data-binary but I am not sure if other
> fields will work.
>
>From a quick scan of the curl man pages, you want to use a separate -F for
each field, and append "type=application/binary" to the upload value. I
think the extra bytes you ware seeing are from URL_ENCODING the zip file.
The -F option is one place the man pages say "further examples and details
in the MANUAL".
/dps
>
> On Monday, March 4, 2019 at 5:01:07 PM UTC-5, Dave S wrote:
>>
>>
>>
>> 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 [email protected] 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 [email protected].
For more options, visit https://groups.google.com/d/optout.