I'm trying to upload a file via REST using PHP curl with the following sample code:
//setting the header
$headerData = "{\"_description\": \"this is a test\", \"_category\": \"Document\"}";
$header = array("Content-type:multipart/form-data","Accept:*/*","CMDBuild-Authorization: $sessionToken", "data: $headerData");
//rest method
$restMethod = "classes/$className/cards/$cardId/attachments";
//add file to post data
$file_name_with_full_path = realpath('./path/to/file.txt');
$postData = array('file' => '@'.realpath($file_name_with_full_path));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
CMDBuild return the following exception: "java.io.IOException: Couldn't determine the boundary from the message!"
Could anyone tell me what's wrong?
I also tried this curl command,
curl "http://.../cmdbuild/services/rest/v1/classes/Employee/cards/1 multipart/form-data" --header "CMDBuild-Authorization: xxx" -X POST --form attachment='{"_description": "test", "_category": "Document"};type=application/json' --form file=@/path/to/file -v
using my cmdbuild address, a corret cmdbuild token and a correct file path, but it doesn't work. Curl returns with this errors:
HTTP/1.1 505 HTTP Version Not Supported
curl (56) recv failure connection reset by peer,
so i tried to add "-0" opt to curl request to set HTTP 1.0 version, but i still get the same errors.
Could anyone help me?
Dear Antonio,
unfortunately we have no experience with PHP but take a look at
this POST, maybe it can help.
Best regards.
-- CMDBuild Team
Previously Antonio wrote:
I'm trying to upload a file via REST using PHP curl with the following sample code:
//setting the header
$headerData = "{\"_description\": \"this is a test\", \"_category\": \"Document\"}";
$header = array("Content-type:multipart/form-data","Accept:*/*","CMDBuild-Authorization: $sessionToken", "data: $headerData");
//rest method
$restMethod = "classes/$className/cards/$cardId/attachments";
//add file to post data
$file_name_with_full_path = realpath('./path/to/file.txt');
$postData = array('file' => '@'.realpath($file_name_with_full_path));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
CMDBuild return the following exception: "java.io.IOException: Couldn't determine the boundary from the message!"
Could anyone tell me what's wrong?
I also tried this curl command,
curl "http://.../cmdbuild/services/rest/v1/classes/Employee/cards/1 multipart/form-data" --header "CMDBuild-Authorization: xxx" -X POST --form attachment='{"_description": "test", "_category": "Document"};type=application/json' --form file=@/path/to/file -v
using my cmdbuild address, a corret cmdbuild token and a correct file path, but it doesn't work. Curl returns with this errors:
HTTP/1.1 505 HTTP Version Not Supported
curl (56) recv failure connection reset by peer,
so i tried to add "-0" opt to curl request to set HTTP 1.0 version, but i still get the same errors.
Could anyone help me?