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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Sending images through SDK not working

miikkae
1-Newbie

Sending images through SDK not working

I have a service that I upload images through. The images are gotten from a recording analytics camera, given a timestamp of the moment and they are gotten to .NET SDK as Streams / byte arrays. I've tried both in ImagePrimitive constructor.

When I use Streams, I get this after my own output, so no actual error message:

   at System.IO.MemoryStream.Read(Byte[] buffer, Int32 offset, Int32 count)

   at com.thingworx.common.utils.StreamUtilities.readStreamToByteArray(Stream stream) in c:\Jenkins\workspace\tw-dotnet-sdk--development\build-stage\dot-net-build\tw-dotnet-sdk\DotNetSDK\common\utils\StreamUtilities.cs:line 76

   at com.thingworx.types.primitives.ImagePrimitive..ctor(Stream byteStream) in c:\Jenkins\workspace\tw-dotnet-sdk--development\build-stage\dot-net-build\tw-dotnet-sdk\DotNetSDK\types\primitives\ImagePrimitive.cs:line 67

When using byte arrays, it doesn't say anything pointing out anything went wrong.

On ThingWorx side I have an InfoTable property, one column for these images and I'm calling a custom service that should put the images to the correct column for the row with given identifier.

Is there some specific thing to do to add Image columns? Shouldn't it work with row[0].Image = imageParam; ?

I check the result of the invokeService call and it returns true, that it should only do, when it reaches no exception on try.. catch statement AND a single row with given identifier is found AND the image is not null.

I've a mashup that should show the Image column as displaying the image and also I've checked the infotable property of that Thing but both show the Image as null.

One thing occurred to me while writing this: I get the infotable row with Resources["InfoTableFunctions"].Query. Can I modify these results directly?

If not, should I always loop through the whole infotable searching for the right row (then, at least, the editing have seemed to work).

Seems not that cost efficient solution to loop through all the rows on each service call.

EDIT: Changed the service to loop the rows through. Now I'm getting images like: <img src="data:image/png;base64,[B@1accf75a"> to the mashup. Any help on how to get this working? In mashup's grid the column's defined to "show image" and I also have a value display that's data is the image but neithers working

2 REPLIES 2

It seems like the MediaCoding of the Stream gotten from the camera is raw, so this might not be ThingWorx error.

I'll try to handle the conversion of the stream and see if it works after that.

Write a code to get the bytes of the image file, normally like jpg or png:

        public byte[] GetPictureData(string imagepath)

        {

            FileStream fs = new FileStream(imagepath, FileMode.Open);

            byte[] byData = new byte[fs.Length];

            fs.Read(byData, 0, byData.Length);

            fs.Close();

            return byData;

        }

Then try to use:

ImagePrimitive ip = new ImagePrimitive(GetPictureData(%your picture path%));

base.setPropertyValue("GraphicStatus", ip);

to set your image type property.

Top Tags