Upload Files to Content via REST or SOAP | Salesforce Developers Blog

I typically spend a few hours a week answering questions on the Force.com Discussion Boards – our forum for developer Q&A. Sometimes issues can be resolved with a couple of sentences (such as this recent question on an exception in the SOAP client stack), other times, I might spend an hour or two coding and testing a solution, as I did yesterday.

The question was pretty straightforward – ‘How do I upload files to Content from a Java client?’. Though it is documented, the answer is not immediately obvious, since the Content data model includes a number of objects, such as ContentDocument, ContentWorkspace and ContentVersion. It turns out that ContentVersion is key – create a ContentVersion object, supplying the path of the document in the PathOnClient field and the document data in VersionData. With Simon Fell‘s blog post showing how it works in Visualforce and Apex as a starting point, I was able to quickly code a solution in Java for both the SOAP and REST variants of the Force.com API.

The full solutions are posted as replies to the original question – check them out, and, if you’re stuck on a tricky problem in future, bring it to the Force.com Discussion Boards – we have a great community of experts there, ready and willing to help!

Stay up to date with the latest news from the Salesforce Developers Blog