Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hello,
I want to show photo from Image Repository in TWX, but photo stored there is saved as base64. I was trying to get that photo via 'loadImage' service, then convert from base64 to jpg with '`data:image/jpg;base64,${response.rows[0].Content}`' and set this as src in 3dImage.
And it works in preview mode, but on mobile it doesn't.
I get an error :
'ERROR, data: ["Could not add 3D image: image_0_3"]; discarding callback; args=["image_0_3","image_0_3","data:image/jpg;base64,/9j/4AAQSkZJ...'
So how can I get image from TWX and set it as 3dImage?
Hi @JT_10028013,
You can store image in ThingWorx server @<Tomcat>\webapps\Thingworx\images folder
Then the images can be accessed using URL such as http://<server>:<port>/Thingworx/images/111.jpg
You can add above image link as an Application Parameter in Studio.
Bind the image URL (parameter) to the Resource of the 3D image.
Make sure the ThingWorx(image) URL is accessible from the View device.
Refer to https://www.ptc.com/en/support/article/cs314282
Have you tried the url from the repo for example
$scope.view.wdg['myimage'].imgsrc=repoURL // from example "/Thingworx/FileRepositories/TakePhoto_Repo/photos/demo/1645196272644.png"
Then you don't have to deal with the content.
This is an example of an upload service in Thingworx
logger.debug("Entering UploadPhoto" );
if (fileName === undefined || fileName === "") {
var d = new Date();
fileName = "Photo-" + d.getTime();
}
// result: STRING
var usename = Resources["CurrentSessionInfo"].GetCurrentUser();
//Create Folder in doesn't exist
try {
me.CreateFolder({
path: '/photos/'+ usename /* STRING */
});
} catch (ex) {
// decide how to inform user
}
me.SaveImage({
path: '/photos/'+ usename + '/'+fileName /* STRING */,
content: imageContent /* IMAGE */
});