Skip to main content
14-Alexandrite
June 22, 2021
Solved

Can we receive a BLOB/binary as is from the request body?

  • June 22, 2021
  • 2 replies
  • 5212 views

I am trying to receive a binary or BLOB as a REST server.

Is it possible to receive the request's body and parse the payload?

I understand using a property name it would be possible but would it be possible to get a handle of the incoming request body directly?

Best answer by VladimirRosu_116627

Hi Soura,

There is a way to do this, and this is by adding the "postParameter" URL parameter to the request:
https://domainme/Thingworx/Things/aaa/Services/bbb?postParameter=nameOfThingWorxServiceParameter
You must create a service named bbb, which must have a parameter named "nameOfThingWorxServiceParameter"
If you do this, you can send the payload from the external system to ThingWorx without wrapping it in the normal JSON format ThingWorx expects ({"nameOfThingWorxServiceParameter":"payload"}.
I use this exactly in the case when I want to send for example JSON payloads from external systems where I can not properly format the body (tested and still working in 9.1.2).

Note that I did not try it with a parameter type BLOB, I think you should try it along this path.

2 replies

15-Moonstone
June 22, 2021

@Soura Have you tried using ContentLoaderFunctions resource in thingworx? You can try using the loadbinary service for getting a binary result.

let params = {
proxyScheme: undefined /* STRING */,
headers: undefined /* JSON */,
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: undefined /* STRING */,
timeout: undefined /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: undefined /* STRING */,
domain: undefined /* STRING */,
username: undefined /* STRING */
};

// result: BLOB
let result = Resources["ContentLoaderFunctions"].LoadBinary(params);

 

Soura14-AlexandriteAuthor
14-Alexandrite
June 29, 2021

Thanks @abjain for your response!

I want to receive a BLOB(inbound). The LoadBinary() is an outbound request. I am more interested in the inbound request, something like a SOAP server. Hope it clarifies.

Support
July 1, 2021

Hi @Soura.

 

LoadBinary should work for your needs.  You would use PostBinary or PutBinary for outbound.

 

Regards.

 

--Sharon

Soura14-AlexandriteAuthor
14-Alexandrite
July 7, 2021

Thanks for your response Sharon @slangley!

The use case is to receive a binary(inbound). LoadBinary() also has a url parameter which makes it go to an end point to receive the binary. Do we have any service to receive binary something like a SOAP server?

 

Regards

Support
July 21, 2021

Hi @Soura.

 

We're still confused.  Please advise which is the source and the target.  We were assuming the target was the ThingWorx side.  Are you trying to pull from a SOAP server?

 

Please provide a little more detail and we'll try to assist.

 

Regards.

 

--Sharon