Post, put or patch of list of media fields

10 views
Skip to first unread message

Cesare Ghirelli

unread,
Mar 14, 2019, 5:36:35 AM3/14/19
to Eve REST Framework
Hello,

I'm sorry to ask, but I'm stuck with this for about a week.
I've the following endpoint:

'dev_test': {
'resource_methods': ['GET', 'POST'],
'item_methods': ['GET', 'PUT', 'PATCH', 'DELETE'],
'resource_title': u"Only for test",
'item_title': u"Only for test",
'item_url': 'regex("[0-9]+")',
'schema': {
'_id': {'type': 'string', 'maxlength': 8},
'titolo': {'type': 'string'},
'documenti': {
'type': 'list',
'schema': {
'titolo': {'type': 'string'},
'documento': {'type': 'media'}
}
}
}
}


EXTENDED_MEDIA_INFO = ['content_type', 'name', 'length', 'md5']
MULTIPART_FORM_FIELDS_AS_JSON = True
AUTO_CREATE_LISTS = True
AUTO_COLLAPSE_MULTI_KEYS = True
RETURN_MEDIA_AS_URL = True
RETURN_MEDIA_AS_BASE64_STRING = False


I'm trying to achieve this whith python requests but with any luck
One of the many test was like this (of course not working, only for example):

import json
import requests

payload = {
'_id': '030000',
'titolo': 'ueeeeee'
}

file = open(r'C:\Windows\System32\calc.exe', 'rb')

headers = {'Content-type': 'application/json'}

res2 = requests.put(
url,
data=payload,
files={
'documenti':
{
'titolo': 'aaaaaa',
'documento': file
}
},
headers=headers
)
print(res2.status_code)




Does anybody achieve this with success? Any hint?

thank you in advance and have a good day,
Cesare
Reply all
Reply to author
Forward
0 new messages