public void UploadDocsWithProperties2(string repo, string folderId, byte[] documentBytes, string fileName, ContentProperty contentProperty = null) { var request = new RestRequest("/" + repo + "/folders/" + folderId + "/documents", Method.POST); request.RequestFormat = DataFormat.Json; request.AddBody(contentProperty); request.AddFileBytes("content", documentBytes, fileName, "application/pdf"); /* RestResponse<bool> * request.AddParameter("object[name]", "object"); * request.AddParameter("object[tag_number]", tagnr); * request.AddParameter("machine[serial_number]", machinenr); * request.AddParameter("machine[safe_token]", safe_token); * request.AddFile("receipt[receipt_file]", File.ReadAllBytes(path), "Invoice.pdf", "application/octet-stream"); */ request.AddHeader("Authorization", DocumentumServiceUtils.CreateBasicBearToken()); RestClient restClient = new RestClient( System.Configuration.ConfigurationManager.AppSettings["documentumUrl"].Replace("{REPO}", repo)); var response = restClient.Execute(request); Log.Info("Called documentum with response: " + response); }
public void UploadDocsWithProperties(IDictionary <string, string> ecf, byte[] documentBytes) { // let's check that all my envelope custom fields are not null foreach (KeyValuePair <string, string> entry in ecf) { if (entry.Value == null) { throw new ApiException(400, "Missing required envelope custom field parameter " + entry.Key + " when calling DocumentumService->uploadDocument"); } } var documentumApi = new DocumentumApi(); ContentProperty contentProperty = new ContentProperty(); contentProperty.properties = new PropertiesType(); contentProperty.properties.r_object_type = ecf[EnvelopeMetaFields.DocumentType]; contentProperty.properties.object_name = ecf[EnvelopeMetaFields.PolicyNumber] + "-" + ecf[EnvelopeMetaFields.FormID]; contentProperty.properties.author_creator = ecf[EnvelopeMetaFields.AuthorCreator]; contentProperty.properties.author_date = ecf[EnvelopeMetaFields.AuthoredDate]; contentProperty.properties.subject = ecf[EnvelopeMetaFields.Subject]; contentProperty.properties.topic_subject = ecf[EnvelopeMetaFields.FormID] + "-" + ecf[EnvelopeMetaFields.FormDescription]; contentProperty.properties.business_record = ecf[EnvelopeMetaFields.BusinessRecord]; string requestHost = System.Configuration.ConfigurationManager.AppSettings["documentumUrl"].Replace("{REPO}", ecf[EnvelopeMetaFields.Repository]); var localVarPath = "/folders/{folderId}/documents?overwrite=true".Replace("{folderId}", ecf[EnvelopeMetaFields.FolderId]); // Create a http request to the server endpoint that will pick up the // file and file description. HttpWebRequest requestToServerEndpoint = (HttpWebRequest)WebRequest.Create(requestHost + localVarPath); string boundaryString = "FFF3F395A90B452BB8BEDC878DDBD152"; // Set the http request header requestToServerEndpoint.Method = WebRequestMethods.Http.Post; requestToServerEndpoint.ContentType = "multipart/form-data; boundary=" + boundaryString; requestToServerEndpoint.KeepAlive = true; requestToServerEndpoint.Headers.Add("Authorization", "Basic " + DocumentumServiceUtils.CreateBasicBearToken()); requestToServerEndpoint.Accept = "application/vnd.emc.documentum+json"; // Use a MemoryStream to form the post data request, // so that we can get the content-length attribute. MemoryStream postDataStream = new MemoryStream(); StreamWriter postDataWriter = new StreamWriter(postDataStream); // Include value from the tag_number text area in the post data postDataWriter.Write("\r\n--" + boundaryString + "\r\n"); postDataWriter.Write("Content-Disposition: form-data; name=\"object\"\r\n"); postDataWriter.Write("Content-Type: application/vnd.emc.documentum+json;charset=UTF-8\r\n\r\n"); postDataWriter.Write(JsonConvert.SerializeObject(contentProperty)); // Include the file in the post data postDataWriter.Write("\r\n--" + boundaryString + "\r\n"); postDataWriter.Write("Content-Disposition: form-data; name=\"content\"\r\n"); postDataWriter.Write("Content-Type: application/pdf\r\n\r\n"); postDataWriter.Flush(); postDataStream.Write(documentBytes, 0, documentBytes.Length); postDataWriter.Write("\r\n--" + boundaryString + "--\r\n"); postDataWriter.Flush(); // Set the http request body content length requestToServerEndpoint.ContentLength = postDataStream.Length; // Dump the post data from the memory stream to the request stream Stream s = requestToServerEndpoint.GetRequestStream(); postDataStream.WriteTo(s); postDataStream.Close(); s.Close(); try { var response = requestToServerEndpoint.GetResponse(); Log.Info("Called documentum with response: " + response); } catch (WebException ex) { using (var stream = ex.Response.GetResponseStream()) using (var reader = new StreamReader(stream)) { throw new ApiException((int)GetHttpStatusCode(ex), "Error calling DocumentumApi=>UploadDocsWithProperties ", reader.ReadToEnd()); } } }