Skip to main content
5-Regular Member
February 11, 2022
Question

Show image from TWX

  • February 11, 2022
  • 2 replies
  • 1718 views

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?

2 replies

16-Pearl
February 15, 2022

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

 

 

16-Pearl
February 18, 2022

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 */
});

  

16-Pearl
November 11, 2025

Thank you! Your post has helped me to show images in Vuforia view app.