Inputs and Binary File Upload Examples

Make HTTP POST, PATCH, and PUT requests using inputs and learn more about uploading binary files.

When you make a request using the HTTP POST, PATCH, and PUT methods, you can use request parameters or a request body. The request body can contain JSON or XML. If you pass resource-specific request parameters and a request body, the request parameters are ignored. Request parameters that aren’t specific to a resource, such as parameters in a bearer token URL and the _HttpMethod parameter, are processed along with the request body. Use bearer token parameters as they are. Don’t add or remove parameters.

To submit a request using request parameters, use a Content-Type header field with the value application/x-www-form-urlencoded.

To submit a request using a request body, use one of these values in a Content-Type header field and in an Accept header field.

  • application/json
  • application/xml

To upload a binary file up to 2 GB (including headers), up to 75 MB for an external repository, or up to 512 MB for bulk conversations, send it as a body part in a multipart/form-data request. You can send the text of a comment (but not a post) as a JSON or XML rich input body part in the same multipart/form-data request. Alternately, you can choose to send that information in request parameters. If you pass both a rich input request body and request parameters, the request parameters are ignored.

To upload multiple binary files in the same call, see Batch Resource.

In version 36.0 and later, you can’t create a feed post and upload a binary file in the same request. Upload files to Salesforce first, and then use the file IDs to attach one or more files to a feed post.

To create a multipart/form-data request, in the head of the request, set the Content-Type HTTP header to multipart/form-data.

For information about HTTP headers, see W3C Form content types, and RFC 2388, which defines the multipart/form-data internet media type.

This table describes the HTTP headers and parameters required in the rich input body part of a multipart/form-data request.

HTTP Headers for Rich Input Body PartHeader Value and ParametersDescription
Content-Dispositionform-data; name="json"The request body for a post or comment. For JSON, the value of name use "json".
Content-Dispositionform-data; name="xml"The request body for a post or comment. For XML, the value of name use "xml".
Content-Typeapplication/json; charset=UTF-8The data format and character set of the request body. For JSON, the value must be application/json.
Content-Typeapplication/xml; charset=UTF-8The data format and character set of the request body. For XML, the value must be application/xml.

Web browsers are typically incapable of making multipart requests when the non-binary parts, such as rich input bodies, have their own Content-Type. To work around this issue, specify a certain Content-Disposition name and Salesforce can read the Content-Type of the rich input part. (You don’t have to specify a Content-Type for the rich input body.)

This table describes the HTTP headers and parameters required in the rich input body part of a multipart/form-data request from a web browser.

HTTP Headers for Rich Input Body Part from Web BrowserHeader Value and ParametersDescription
Content-Dispositionform-data; name="feedElement"To post a feed element with a binary file (in version 35.0 and earlier), the value of name must be "feedElement".
Content-Dispositionform-data; name="comment"To post a comment with a binary file, the value of name must be "comment".
Content-Dispositionform-data; name="photo"To upload an employee, user, or group photo, the value of name must be "photo".
Content-Dispositionform-data; name="file"To upload a file to the Files home or an external repository, the value of name must be "file".
Content-Dispositionform-data; name="folderItem"To upload a file to a folder, the value of name must be "folderItem".
Content-Dispositionform-data; name="ManagedContentInputParam"To upload a piece of managed content, the value of name must be "ManagedContentInputParam".
Content-Dispositionform-data; name="ManagedContentVariantInputParam"To update a managed content variant, the value of name must be "ManagedContentVariantInputParam".

This table describes the HTTP headers and parameters required in the binary upload body part of a multipart/form-data request.

HTTP Headers for Binary Upload Body PartHeader Value and ParametersDescription
Content-Dispositionform-data; name="feedElementFileUpload"; filename={string}To post a feed element with a binary file (in version 35.0 and earlier), the value of name must be "feedElementFileUpload".
Content-Dispositionform-data; name="feedElementFileUpload"; filename={string}To post a comment with a binary file, the value of name must be "feedElementFileUpload".
Content-Dispositionform-data; name="fileUpload" filename={string}To upload a user or group photo, the value of name must be "fileUpload".
Content-Dispositionform-data; name="fileData" filename={string}To upload a file to the Files home or to upload a file to an external repository, the value of name must be "fileData".
  • Note: Specify a filename parameter and value. However, Salesforce uses the value of the title property of the File Input or the metadata of the Files Connect Item Input as the file name, not the value of the filename parameter.
Content-Dispositionform-data; name="audioFileData" filename={string}To upload an audio file, the value of name must be "audioFileData". If you specify this value, don’t specify recordingURL or name or the request will fail.
Content-Dispositionform-data; name="contentData" filename={string}To upload a piece of managed content or update a managed content variant, the value of name must be "contentData".
Content-Dispositionform-data; name="file" filename={string}To create a translation workbench import job, the value of name must be "file".
Content-Typeapplication/octet-stream; charset=ISO-8859-1The media type and character set of the binary file.

Spacing and carriage returns and line feeds (CRLF) are important. For example, this line requires spaces: Content-Disposition: form-data; name="feedItemFileUpload"; title="2012_q1_review.ppt". If you used CRLF instead of spaces, you would receive an error.

This example uses the /chatter/feed-elements resource to post a new feed item (which is a type of feed element), upload a binary file, and attach it to the new feed item. This example uses cURL.

Here is the same example in a different format so you can see the request body parts.

This example applies to version 35.0 and earlier.

This example uses the /chatter/feed-elements/batch resource to post a batch of feed elements, upload two binary files, and attach them to the feed elements in the batch. Include the information about the binary parts in the request body. This example uses cURL.

Here is the same example formatted to show the request body parts.

The binary part names in the binaryPartNames properties must match the binary part names in the name properties of the binary request parts.

This example uses the /chatter/feed-elements/{feedElementId}/capabilities/comments/items resource to post a comment to a feed item and upload a binary attachment using cURL.

Here is the sample example formatted to see the request body parts.

This example is a generic batch request to /connect/batch that contains two subrequests. Each subrequest comments on a feed item and uploads a binary file to the comment.

Include the request body of each subrequest in the richInput properties.

Also include information about the binary parts in the binaryPartName and binaryPartNameAlias properties.

Here is the cURL example.

Here is the multipart/form-data request body.

This example uses the /connect/user-profiles/{userId}/photo resource to upload a user profile photo and crop it using cURL.

Here is the same example formatted to see the request body parts.

This example uses the /connect/files/users/{userId} resource to upload a file to the Files home using cURL.

Here is the same example formatted to see the request body parts.

This example uses the /connect/content-hub/repositories/{repositoryId}/folders/{repositoryFolderId}/items resource to upload a file to an external repository using cURL.

Here is the same example formatted to see the request body parts.

This example uses the /voicecalls/{voiceCallId}/audio_upload resource to upload an audio file using cURL.

This example uses the /voicecalls/{voiceCallId}/audio_upload resource to upload an audio file using cURL.

This example uses the /connect/cms/contents resource to upload a piece of managed content. This resource is available only for enhanced CMS workspaces.

This example uses the /connect/cms/contents/variants/{variantId} resource to update a managed content variant. This resource is available only for enhanced CMS workspaces.

This example uses the /connect/i18n/twb/import resource to create an asynchronous translation workbench import job using cURL.

Here is the same example formatted for a REST client. A valid file must exist in the path you specify.