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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Update Image property via REST request

drieder
15-Moonstone

Update Image property via REST request

Hello everyone,

 

I have an entity with an image property which I would like to update from my edge device (note that I am working with the java sdk). Since it is actually a live stream from a camera I will update this image frequently (something like 2 or more per second). 

 

It was suggested to me to use the fileTransferSubsystem for that, but I would prefer doing that with a PUT Rest request. Can anyone explain how to exactly send images like this? I am using postman for testing and using the following headers and parameters:

 

address: https://serverIP:Port/Thingworx/Things/Camera/Properties/CurrentImage

accept and Content-type: application/json

appKey: theAppkey

 

body: {"CurrentImage": binaryEncodedImage}

 

I get a 200 OK response but the image is not updated. I think my image might be wrongly decoded so my main question is, which representation of the image should I put in the json body?

 

I get the images through a GET request from another server so in my java program the image can either be represented as a byte[] array, an inputStream or a simple Image object. For postman I also tried it with a .jpg as a binary.

 

I am thankfull for any suggestions.

 

Kind Regards,

Dominik

 

Edit: I already changed the configuration of the PlatformSubsystem to allow Request Method Switch and disabled filter content type

 

1 ACCEPTED SOLUTION

Accepted Solutions
cbuse
12-Amethyst
(To:drieder)

The image should be base64 format. Here is a working example: https://community.ptc.com/t5/ThingWorx-Developers/Uploading-an-image-through-REST-api-to-an-image-property/td-p/506613

 

Considering your use case with live stream from a camera, take a look at the video streaming widget: https://community.ptc.com/t5/ThingWorx-Developers/How-to-display-a-live-vedio-stream-on-Thingworx-mashup/m-p/507500/highlight/true#M5320

 

Best regards,

Cristina

 

View solution in original post

2 REPLIES 2
cbuse
12-Amethyst
(To:drieder)

The image should be base64 format. Here is a working example: https://community.ptc.com/t5/ThingWorx-Developers/Uploading-an-image-through-REST-api-to-an-image-property/td-p/506613

 

Considering your use case with live stream from a camera, take a look at the video streaming widget: https://community.ptc.com/t5/ThingWorx-Developers/How-to-display-a-live-vedio-stream-on-Thingworx-mashup/m-p/507500/highlight/true#M5320

 

Best regards,

Cristina

 

drieder
15-Moonstone
(To:cbuse)

Thank you, I wasn't converting byteArray to base64 String

Top Tags