I've been struggling with a problem for quite a while so I figured I would take a set back and examine the bigger picture. Is it possible to use Salesforce APEX trigger to get the body from an attachment (image) that is being added/modified and send that through HTTP POST with a callout to an external server where it is then saved to that server.

I have been working to use a node js server to decode the body Blob data and write it to a file on the server where node is, but my images are either corrupt outright or completely black in color, despite being the same dimensions as the original.

To put it as simple as possible: Attachment is Modified -> APEX Trigger -> HTTP POST from Salesforce to External server -> File is written on server.

  • 1
    Did you base-64 encode it in Apex and then base-64 decode it in node.js? Did you set the right headers so that node.js knows its encoded? You can't send binary data over the wire, as Apex Code doesn't support that, but you can set Content-Transfer-Encoding to "base64", and use EncodingUtil.base64encode(Blob). Of course, it will bloat your file size by 33%, so your maximum callout size will shrink a bit.
    – sfdcfox
    Commented Jun 18, 2015 at 22:21
  • @sfdcfox Yes, I've been doing the Encode/Decode of the data to base64. I'm using Nodes 'new Buffer(encodedString, "base64")' to do the decoding part of it. That's why I'm thinking that something might be funky with either the encode side or the decode side... Commented Jun 19, 2015 at 14:02

1 Answer 1


If your attachment size is less than 3 MB always apex can be considered and should work .The maximum size of body that apex callout can handle is 3MB .

The reason why your file is corrupting may be because it is not base64 decoded properly .

The other architecture I can think of is as below

1)From SFDC invoke a small callout to node .

2)The callout to node will invoke the SFDC REST API to pull file directly .

This can be used when you have larger files .

  • I did not know of the 3 MB maximum size, that is very useful information. Does Node regularly have issues with decoding base64 using the 'new Buffer' method? Commented Jun 19, 2015 at 14:05

You must log in to answer this question.

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