CMDBuild Forum

Upload of an Attachment via REST

Webservice document says:

 

POST .../classes/Building/cards/64/attachments HTTP/1.1 

[various headers]

Content-Type : multipart/form-data 

== Part, name : "attachment", content-type : "application/json" == 

{

   _description : this is a test,

   _category : Image,

}

====

== Part, name : "file", content-type : "*/*" == binary

====

I'm testing with python, tested create card, relation. But I don't understand how to upload of an attachment. What does == Part, name : "attachment", content-type : "application/json" ==  and Part, name : "file", content-type : "*/*" == binary parts mean.

 

Let's say I have attachment upload part in my Python script:

cmdbuild_url = "..../classes/Servers/cards/64/attachments"

data = {'_description': 'this is a test', '_category': 'Image'}

headers = {'Content-type': 'multipart/form-data', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid, 'data': 'data'}

request = requests.post(cmdbuild_url, data=json.dumps(data), headers=headers)

 

How I define file wich I want to upload?

Dear ruji,
 
this is the way how it can be done using cURL:
 
curl "http://.../cmdbuild/services/rest/v2/classes/Employee/cards/1 multipart/form-data" --header "CMDBuild-Authorization: ..." -X POST --form attachment='{"_description": "test", "_category": "Document"};type=application/json' --form file=@/path/to/file -v
 
Best regards.
 
-- CMDBuild Team
 
Previously ruji wrote:

Webservice document says:

 

POST .../classes/Building/cards/64/attachments HTTP/1.1 

[various headers]

Content-Type : multipart/form-data 

== Part, name : "attachment", content-type : "application/json" == 

{

   _description : this is a test,

   _category : Image,

}

====

== Part, name : "file", content-type : "*/*" == binary

====

I'm testing with python, tested create card, relation. But I don't understand how to upload of an attachment. What does == Part, name : "attachment", content-type : "application/json" ==  and Part, name : "file", content-type : "*/*" == binary parts mean.

 

Let's say I have attachment upload part in my Python script:

cmdbuild_url = "..../classes/Servers/cards/64/attachments"

data = {'_description': 'this is a test', '_category': 'Image'}

headers = {'Content-type': 'multipart/form-data', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid, 'data': 'data'}

request = requests.post(cmdbuild_url, data=json.dumps(data), headers=headers)

 

How I define file wich I want to upload?

 

I tried that cURL command, used my cmdbuild address, CMDBuild-Authorization and filepath. I can upload file but for some reason it doesn't add file under specified category or doesn't add specified description. File just goes under attachment without description.
 
Now I can upload file with python script too but same problem, category and description doesn't work. But that is my script.
 
Do anybody know why that cURL command doesn't work?
 
 
Previously Tecnoteca wrote:
Dear ruji,
 
this is the way how it can be done using cURL:
 
curl "http://.../cmdbuild/services/rest/v2/classes/Employee/cards/1 multipart/form-data" --header "CMDBuild-Authorization: ..." -X POST --form attachment='{"_description": "test", "_category": "Document"};type=application/json' --form file=@/path/to/file -v
 
Best regards.
 
-- CMDBuild Team
 
Previously ruji wrote:

Webservice document says:

 

POST .../classes/Building/cards/64/attachments HTTP/1.1 

[various headers]

Content-Type : multipart/form-data 

== Part, name : "attachment", content-type : "application/json" == 

{

   _description : this is a test,

   _category : Image,

}

====

== Part, name : "file", content-type : "*/*" == binary

====

I'm testing with python, tested create card, relation. But I don't understand how to upload of an attachment. What does == Part, name : "attachment", content-type : "application/json" ==  and Part, name : "file", content-type : "*/*" == binary parts mean.

 

Let's say I have attachment upload part in my Python script:

cmdbuild_url = "..../classes/Servers/cards/64/attachments"

data = {'_description': 'this is a test', '_category': 'Image'}

headers = {'Content-type': 'multipart/form-data', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid, 'data': 'data'}

request = requests.post(cmdbuild_url, data=json.dumps(data), headers=headers)

 

How I define file wich I want to upload?

 

 

Hello, did you find a solution ruji.sepp?
How to define that multipart request in order to upload an attachment?