I am trying to update the contents of a file in alfresco server using C++ rest sdk. I am using the alfresco CMIS url to send the request.To be more specific it is Alfresco CMIS browser binding.I have to stick to browser binding not atom binding.
When I send the request it always updates the version of the file not the contents. I am sending the contents in the request body.Below is my code
void UpdateFileContent()
{
concurrency::streams::basic_istream<unsigned char> fileStream = file_stream<unsigned char>::open_istream("C:\Desktop\Sample.txt").get();
concurrency::streams::stringstreambuf streamBuffer;
fileStream.read_to_end(streamBuffer).get();
std::string textFile = move(streamBuffer.collection());
fileStream.close();
streamBuffer.close();
std::string textBoundary = "--FORMBOUNDARY--";
std::string textBody = "";
textBody += "--" + textBoundary + "\r\n";
textBody += "Content-Disposition:form-data;name=Sample;filename=Sample\r\n";
textBody += "Content-Type: application/octet-stream\r\n\r\n";
textBody +=textFile+"\r\n";
textBody += "--" + textBoundary + "--\r\n";
web::uri_builder builder(U("http://Alfresco-Server:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Sites/"));
builder.append_path(U("siteName/documentLibrary/FolderName/Sample3.doc"));
builder.append_query(U("alf_ticket"),ticket);
builder.append_query(U("cmisaction"),U("update"));
builder.append_query(U("propertyId[0]"),U("cmis:name"));
builder.append_query(U("propertyValue[0]"),U("SampleFileUpdate"));
http_client client(builder.to_string());
http_request req;
req.set_method(methods::POST);
req.headers().set_content_type(L"multipart/form-data;boundary=--FORMBOUNDARY--");
req.headers().set_content_length(textBody.length());
req.set_body(textBody);
http_response response = client.request(req).get();
std::cout<<response.status_code();
}
The same code works for uploading a new file if I change the cmisaction to createDocument. Please give me a solution to update the contents of a file residing in alfresco throught C++ rest SDK
This might help you..