I'm having an issue uploading attachments via the REST API. When trying to upload attachment data (i.e. data about the attachment and the associated base64 binary data) I'm getting a 400 result (Bad Request) with a message like so:
Illegal Request
You have sent us an Illegal URL or an improperly formatted request.
My posted request body looks like this:
--boundary_string_1414605653846
Content-Disposition: form-data; name="entity_attachment";
Content-type: application/json
{"ParentId":"a01J000000gmQlRIAU","Name":"Troubleshooting Request","OwnerId":"005J000000253nKIAQ"}
--boundary_string_1414605653846
Content-Type: application/octet-stream
Content-Disposition: form-data; name="Body"; filename="test.txt"
dGVzdA==
--boundary_string_1414605653846--
Relevant header information:
Request Method:POST
Content-Type:multipart/form-data; "boundary_string_1414605653846"
I used the Salesforce Insert/Update Blob Tutorial to get to the point where I am. Note that their example only interacts with the Document type (not Attachment). However, I tried copying their Document Insert example line-by-line and I still received the 400 Bad Request error.
One other piece of information is that I am not uploading an actual file, but rather a large base64 encoded string.
Best Answer
You can do this using forcetk if you are planning to do this in javascript
here is sample code -
here is internal forcetk implementation for sf blob [link - https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/blob/master/forcetk.js] -