Community Tip - You can change your system assigned username to something more personal in your community settings. X
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
Solved! Go to Solution.
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:
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:
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?
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?
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?
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.
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