1

I have a requirement to post PDF files from Salesforce to an endpoint. On looking into how to achieve this using APEX I came across this article about 'multipart/form-data'.

For my requirement I've been informed that I should use a Content-Type of "application/octet-stream" instead. As the above blog provides a workaround for 'multipart/form-data', I wondered for sending the base64Encoded string VersionData of a ContentVersion as the body of a HTTP Post (using "application/octet-stream") works are there any known issues that could occur with this and should be considered? Should the same process provided in the blog on 'multipart/form-data' be used and just change the Content-Type or is it completely unnecessary as files sent through "application/octet-stream" have no known issues (governor limits) that I'm aware of.

Thanks in advance for any help on this. It's a sanity check on "application/octet-stream".

1 Answer 1

2

application/octet-stream doesn't have the "headers inside the body" type considerations to worry about, so you don't have to worry about base-64 conversion:

ContentVersion cv = [SELECT VersionData FROM ContentVersion WHERE ...];
HttpRequest req = new HttpRequest();
req.setBodyAsBlob(cv.VersionData);

This also means that you can send larger payloads (up to nearly Limits.getLimitHeapSize()) instead of suffering the 3:4 ratio that base-64 offers (i.e. 3 bytes of binary data becomes 4 bytes of encoded data), which reduces the maximum payloads by about 25% (for synchronous code, 4.5MB vs 6MB).

1
  • Thanks @sfdcfox This is great to know. I was thinking it may have been ok but was curious after coming across the 'multipart/form-data' blog if any similar considerations would be required. Thanks for your help on this.
    – RedQueries
    Dec 10, 2021 at 16:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .