The first part of the request message body contains non–binary field data such as the Description or Name. The second part of the message contains the binary data of the file that you're uploading.
This section contains the syntax and code for creating a new Document. In addition to the binary data of the file itself, this code also specifies other field data such as the Description, Keywords, Name, and so on.
curl https://instance name.salesforce.com/services/data/v23.0/sobjects/Document/ -H "Content-Type: multipart/form-data; boundary=\"boundary_string\"" --data-binary @newdocument.json -H "Authorization: OAuth token" -H "X-PrettyPrint:1"
This code is the contents of the file newdocument.json.
--boundary_string
Content-Disposition: form-data; name="entity_document";
Content-Type: application/json
{
"Description" : "Marketing brochure for Q1 2011",
"Keywords" : "marketing,sales,update",
"FolderId" : "005D0000001GiU7",
"Name" : "Marketing Brochure Q1",
"Type" : "pdf"
}
--boundary_string
Content-Type: application/pdf
Content-Disposition: form-data; name="Body"; filename="2011Q1MktgBrochure.pdf"
Binary data goes here.
--boundary_string--
{
"id" : "015D0000000N3ZZIA0",
"errors" : [ ],
"success" : true
}
{
"fields" : [ "FolderId" ],
"message" : "Folder ID: id value of incorrect type: 005D0000001GiU7",
"errorCode" : "MALFORMED_ID"
}
This section contains the syntax and code for updating an existing Document. In addition to the binary data of the file itself, this code also updates other field data such as the Name and Keywords.
curl https://instance name.salesforce.com/services/data/v23.0/sobjects/Document/015D0000000N3ZZIA0 -H "Authorization: OAuth token" -H "X-PrettyPrint:1" -H "Content-Type: multipart/form-data; boundary=\"boundary_string\"" --data-binary @UpdateDocument.json -X PATCH
This code is the contents of the file UpdateDocument.json.
--boundary_string
Content-Disposition: form-data; name="entity_content";
Content-Type: application/json
{
"Name" : "Marketing Brochure Q1 - Sales",
"Keywords" : "sales, marketing, first quarter"
}
--boundary_string
Content-Type: application/pdf
Content-Disposition: form-data; name="Body"; filename="2011Q1MktgBrochure.pdf"
Updated document binary data goes here.
--boundary_string--
This section contains the syntax and code for inserting a new ContentVersion. In addition to the binary data of the file itself, this code also updates other fields such as the ReasonForChange and PathOnClient. This message contains the ContentDocumentId because a ContentVersion is always associated with a ContentDocument.
curl https://instance name.salesforce.com/services/data/v23.0/sobjects/ContentVersion-H "Content-Type: multipart/form-data; boundary=\"boundary_string\"" --data-binary @c:\CurlTest\NewContentVersion.json -H "Authorization: OAuth token" -H "X-PrettyPrint:1"
--boundary_string
Content-Disposition: form-data; name="entity_content";
Content-Type: application/json
{
"ContentDocumentId" : "069D00000000so2",
"ReasonForChange" : "Marketing materials updated",
"PathOnClient" : "Q1 Sales Brochure.pdf"
}
--boundary_string
Content-Type: application/octet-stream
Content-Disposition: form-data; name="VersionData"; filename="Q1 Sales Brochure.pdf"
Binary data goes here.
--boundary_string--
{
"id" : "068D00000000pgOIAQ",
"errors" : [ ],
"success" : true
}
Following are some considerations for the format of a multipart message when you insert or update blob data.