cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

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

Soura
13-Aquamarine

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

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

13 REPLIES 13
abjain
13-Aquamarine
(To:Soura)

@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);

 

Soura
13-Aquamarine
(To:abjain)

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.

slangley
23-Emerald II
(To:Soura)

Hi @Soura.

 

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

 

Regards.

 

--Sharon

Soura
13-Aquamarine
(To:slangley)

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

slangley
23-Emerald II
(To:Soura)

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

Soura
13-Aquamarine
(To:slangley)

Hi Sharon @slangley,

Yes, the target is ThingWorx platform.

Let's say in this example, the SOAP server is trying to push a binary data to ThingWorx. So, the SOAP server acts as client pushing data to a WSDL endpoint(or REST endpoint) on TWX platform which should receive the xml. Let me know if its clearer now.

 

Regards

slangley
23-Emerald II
(To:Soura)

Hi @Soura.

 

It sounds like you may be complicating things.  Take a look at this community post to see if it helps.

 

Regards.

 

--Sharon

 

 

Soura
13-Aquamarine
(To:slangley)

Hi @slangley ,

I apologize if I couldn't make it more clearer to you. The idea is to receive a BLOB or binary without knowing the input payload name. Read the incoming data from the incoming HTTP stream/body. In my case we do not know in advance the incoming BLOB variable name.

Regards

slangley
23-Emerald II
(To:Soura)

Hi @Soura.

 

Before you can consume the data, you need to determine what needs to be done with it once you receive it.  For example, you could create a service within ThingWorx to parse the data for your needs  Or you could use one of our SDK's for manipulating the data into the format needed for consuming into ThingWorx. 

 

If you can provide further details of your intent, we may be able to assist further.

 

Regards.

 

--Sharon

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.

Soura
13-Aquamarine
(To:VladimirRosu)

Thanks @VladimirRosu , This is the solution if we know the incoming parameter name("nameOfThingWorxServiceParameter") and agree with the sender to have this name. But if it comes as a incoming SOAP server call where TWX is acting as a SOAP server end point, then we would want to have a handle at the incoming HTTP stream.

I will accept your solution and clarify with support team.

Regards

Hi @Soura , yes, that's correct.

But, you do not need necessarily to know the incoming parameter name, just to make sure the sender is sending this as part of the URL. Modifying the URL is relatively easy to do in these kinds of situations. So the only thing to do would be to 1: decide on a service input parameter name (whatever you want) and 2. add that parameter name to the URL you're accessing.

Now, as far as I know (and probably I need to be corrected), a SOAP request needs to contain all the proper XML formatted structure in its body and the SoapAction as a header. ThingWorx won't be able to intercept the SoapAction header, since it's too high level.

Isn't it possible to generate a REST-style call from your platform/app? (so that you don't need to treat TWX as SOAP endpoint, which is not)

slangley
23-Emerald II
(To:slangley)

Hi @Soura.

 

If you feel your question has been answered, please mark the appropriate response as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

Top Tags