+ Start a Discussion
Nevil shuklaNevil shukla 

I have inserted ContentVersion through REST API from C# code

Below is the C# code to insert content version through REST API - 

var client = new RestClient("https://yourInstance/services/data/v40.0/sobjects/ContentVersion");
                var request = new RestRequest(Method.POST);
                request.AddHeader("authorization", "Bearer token");
                request.AddHeader("Content-Type", "application/octet-stream");
                request.AddParameter("multipart/form-data; boundary=\"boundary_string\"", "--boundary_string\r\nContent-Disposition: form-data; name=\"entity_content\";\r\nContent-Type: application/json\r\n\r\n{\r\n\t\"Title\": \"My Uploaded File\",\r\n    \"PathOnClient\" : \"image.png\",\r\n\t\"Origin\": \"H\"\r\n}\r\n\r\n--boundary_string\r\nContent-Type: application/octet-stream\r\nContent-Disposition: form-data; name=\"VersionData\"; filename=\"image.png\"\r\n\r\nR0lGODlhGAAVAPcAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwMDcwKbK8GN9rXOGtXuOtYSWvYyexpSmxqWuzq221rW+1r3H3sbP3s7X597f7+fn7+/v9/f3/////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/78KCgpICAgP8AAAD/AP//AAAA//8A/wD//////widADUIHEiwoMGDCBMqXMiwYIMFDRFaYNCgQkSDECJMgHCx4IILGBRkaJjBgkkLExgIbCDhpIWRBx8wcEDTwQSBFGo6mImQggIJCicsoJDwQgMHGAxm2GmBYYSPBDEsiABzYQYFSQdezcqQQgOBFixqeHCzIVkNT6dm8EpSgYWjGJYyqLCAa0ILC34SFLqgqVUJFwxikFC1o+HDiAsGBAA7\r\n\r\n--boundary_string--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Content Version was inserted successfully with content document. But when I tried to view the uploaded content version with above code, I did not able to see the preview and not able to see the actual content even after downloading the file. After download I was able to see the content that I passed as base64 as shown in the above code in AddParameter value.

Could anybody guide me what am I missing to see the actual content ?