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

Uploading an image through REST api to an image property

måkerman
4-Participant

Uploading an image through REST api to an image property

Hello!

If I set up a property as an Image, how do I upload an image to that property using the REST api.

I have tried binary using Postman, I have tried base64, and several other. Usually I get 403 Request Forbidden response.

Application key is set. The problem is how to actually do the PUT request.

/Magnus

1 ACCEPTED SOLUTION

Accepted Solutions
posipova
20-Turquoise
(To:måkerman)

You would need the following headers: content-type, Accept, appkey.

You would send the image as application/json

For example:

The image will be in json:

Hint: you may use your browser dev tools (Chrome - f12) to see the REST call structure when assigning an image property through the composer:

Scrolling down to the  request-payload, you can view the source:

View solution in original post

6 REPLIES 6
posipova
20-Turquoise
(To:måkerman)

You would need the following headers: content-type, Accept, appkey.

You would send the image as application/json

For example:

The image will be in json:

Hint: you may use your browser dev tools (Chrome - f12) to see the REST call structure when assigning an image property through the composer:

Scrolling down to the  request-payload, you can view the source:

View solution in original post

måkerman
4-Participant
(To:posipova)

Hello Polina, and thank you!

I tried the exact way you explained and I got mixed result. The image do change in the property but I also get (500) Internal message response.

And the logging of the pimage property does not work even if the image is changed.

Do you know what it can mean?

Screen Shot 2017-11-30 at 14.59.54.png

posipova
20-Turquoise
(To:måkerman)

Are you placing it as a PUT request? Is the appkey you are using connected to the Administrator user /has sufficient permissions? Are you passing it as json? I saw this error with a REST service request  rejected (HTTP 500 Internal Server Error) by the TW platform when a text value embedded in the JSON payload contains Line Feeds (ASCII 10),,, What is your ThingWorx platform version?

måkerman
4-Participant
(To:posipova)

User has sufficient permissions?

I have created a new user with read/write permission to the Thing. I connected a key to that user and that key is used for upload.

Are you passing it as json?

Yes.

What is your ThingWorx platform version?

A very reacent installation of the ThingWorx Trial Bundle.

About line feeds: I also try the exact same thing with a Python program using requests package, like requests.put(url, json). Then I get the exact same result.

What about the image types, could that matter?

posipova
20-Turquoise
(To:måkerman)

Are you using Chrome?

Try this.. Open your dev tools, upload your image to the property manually through the composer, then copy the source from the request payload and try to paste it exactly as it is in your REST call.

måkerman
4-Participant
(To:måkerman)

The problem was due to access rights. I used a different user to upload and that user did not have access to ThingworxPersistenceProvider.

I found the solution by reading this thread:

REST API property value update do not fire value change event

Announcements