How to HTTP POST pure binary data to external system?

Andy-L
Tera Contributor

Hi, I'd like to send an attachment from ServiceNow to an external system - ZenDesk. This first requires the file to be uploaded using HTTP POST.

I was using the RestMessageV2 api - it works for text but not for binary. I guess the binary data is being corrupted by the Java String due to invalid UTF.

The curl example is below (and here ). It uses a pure binary format (application/binary), and specifically does not interpret base64 , MIME etc.

curl "https://{subdomain}.zendesk.com/api/v2/uploads.json?filename=myfile.dat" \

  -v -u {email_address}:{password} \

  -H "Content-Type: application/binary" \

  --data-binary @file.dat -X POST

(Out of curiosity I did try to POST a mutlpart/form-data to ZenDesk using Curl but ZenDesk just interpreted the entire message as the file including control codes)

I've looked briefly at the httpClient classes:

  •     Packages.org.apache.commons.httpclient.HttpClient();
  •     GlideHTTPClient();

But I've seen comments that the latter only exposes string functions.

I've seen some info on saveResponseBodyAsAttachment() I guess I'm looking for something like sendAttachmentAsRequestBody()

or ideally just a way to do a simple pure binary HTTP post.

Any ideas ?

I've also looked from the ZenDesk end, to see if it can accept Base64/Mime but there does not seem to be any options there (No SOAP API etc)

1 ACCEPTED SOLUTION
6 REPLIES 6

srinivasthelu
Tera Guru

Hi Srini, yes I've seen that. That is for   binary on the response,, I want to send binary on the request.


Hi Looks promising but according to   this ( setRequestBodyFromAttachment - How does it work?   ) it sends Base64 ? Can you confirm? I need a pure binary post...