REST API - Create Document - HTTPClient
I have a auth ticket, and have set a link / URI to ContentServer.
- I can get nodes
- I can create folders and categories
- I don't know how to upload a document. See the code below.
What is needed to fix this?
//Create MultiPart Form Data MultipartFormDataContent mainRequest = new MultipartFormDataContent(); //Setting the Post parameters Dictionary<string, string> abc = new Dictionary<string, string>(); abc.Add("type", "144"); abc.Add("parent_id", parentId.ToString()); abc.Add("name", "testDocument"); FormUrlEncodedContent form = new FormUrlEncodedContent(abc); //Setting the Document byte[] bb = File.ReadAllBytes("c:\\temp\\testWord.docx"); ByteArrayContent file = new ByteArrayContent(bb); file.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); //Adding preps to FormData mainRequest.Add(form); mainRequest.Add(file, "file"); //Call //500 internal error. HttpResponseMessage response = _client.PostAsync("nodes", mainRequest).Result; response.EnsureSuccessStatusCode();
Tagged:
1
Comments
-
Answered my own question, I was rather close. Hope I help someone else with this.
2 changes:
//Setting POST parameters, no dictionary but stringcontents StringContent type = new StringContent("144"); StringContent parent = new StringContent(parentId.ToString()); StringContent name = new StringContent("asdfasd.docx"); //name in content server //Add Parameters and Document mainRequest.Add(type, "\"type\""); mainRequest.Add(parent, "\"parent_id\""); mainRequest.Add(name, "\"name\""); mainRequest.Add(file, "file", "c:\\temp\\testWord.docx"); //this has also changed, add filename.
0 -
This was really helpful, thanks. Do you happen to have sample code for updating/adding Categories to a document?
0 -
Hi Paul or Kevin,
Kindly provide me the basic apis on open text like authentication, add document, add folder and search documents using restful api. I am new to open text.
Thanks in advance
Regards,
Sunil0 -
Hi Paul or Kevin,
Kindly provide me the basic apis on open text like authentication, add document, add folder and search documents using restful api. I am new to open text.
Than0 -
Hi Paul or Kevin,
Kindly provide me the basic apis on open text like authentication, add document, add folder and search documents using restful api. I am new to open text.
Thanks in advance
Sunil0 -
Hi Paul or Kevin,
Kindly provide me the basic apis on open text like authentication, add document, add folder and search documents using restful api. I am new to open text.
Thanks in advance
Sunil0
Categories
- All Categories
- 108 Developer Announcements
- 53 Articles
- 106 General Questions
- 144 IM Services
- 43 OpenText Hackathon
- 32 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 899 Cloud Fax and Notifications
- 77 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 120 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management