I am trying to post to a Salesforce.com REST api that is expecting the following request -
POST /services/data/v33.0/chatter/feed-elements HTTP/1.1 Authorization: OAuth 00DRR0000000N0g!... User-Agent: Jakarta Commons-HttpClient/3.0.1 Host: instance_name Content-Length: 845 Content-Type: multipart/form-data; boundary=a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq Accept: application/json --a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq Content-Disposition: form-data; name="json" Content-Type: application/json; charset=UTF-8 { "body":{ "messageSegments":[ { "type":"Text", "text":"Please accept this receipt." } ] }, "capabilities":{ "content":{ "description":"Receipt for expenses", "title":"receipt.pdf" } }, "feedElementType":"FeedItem", "subjectId":"005RR000000DmOb" } --a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq Content-Disposition: form-data; name="feedElementFileUpload"; filename="receipt.pdf" Content-Type: application/octet-stream; charset=ISO-8859-1 ...contents of receipt.pdf... --a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq--I tried to write the following code but seems the two different content-type can not be recognised -
xhr.open("POST", postUri); xhr.setRequestHeader("Authorization", authHeader); xhr.setRequestHeader('enctype', 'multipart/form-data'); var data2send = { json: jsonText, feedElementFileUpload: imageBlob }; xhr.send(postBody);The major issue seems to be that the service can not recognise the first part (json) is application/json type. How can I indicate the different content-type for the two parts?