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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

How to create media entity dynamically?

done11
1-Newbie

How to create media entity dynamically?

Hi,

I have a use case in which i wanted to create media entity dynamically.

please suggest.

Thanks in advance!

2 REPLIES 2
jamesm1
5-Regular Member
(To:done11)

You can do this, but as far as i know this is not supported and is not part of the standard Thingworx API.

You need to create a service that makes a PutJSON request to your thingworx media entities uri, i.e.:

http://[YOUR THINGWORX SERVER]/Thingworx/MediaEntities?reason=header%20%3A%20name%20%3A%20updated%2C%20content%20%3A%20updated%0A


with the following JSON content:


{

  "content": "[BASE64 ENCODED IMAGE]

  "tags": [],

  "documentationContent": "",

  "runTimePermissions": {

  "permissions": []

  },

  "description": "",

  "name": "[MEDIA ENTITY NAME]",

  "aspects": {},

  "designTimePermissions": {

  "Update": [],

  "Create": [],

  "Read": [],

  "Metadata": [],

  "Delete": []

  },

  "avatar": "",

  "homeMashup": ""

}

Edit: If the image is available via  a URL, you can use the LoadMediaEntity service:

var params = {

  proxyScheme: undefined /* STRING */,

  headers: undefined /* JSON */,

  ignoreSSLErrors: undefined /* BOOLEAN */,

  useNTLM: undefined /* BOOLEAN */,

  description: undefined /* STRING */,

  workstation: undefined /* STRING */,

  useProxy: undefined /* BOOLEAN */,

  proxyHost: undefined /* STRING */,

  url: undefined /* STRING */,

  timeout: undefined /* NUMBER */,

  tags: undefined /* TAGS */,

  proxyPort: undefined /* INTEGER */,

  password: undefined /* STRING */,

  domain: undefined /* STRING */,

  name: undefined /* STRING */,

  username: undefined /* STRING */

};

// result: IMAGELINK

var result = Resources["ContentLoaderFunctions"].LoadMediaEntity(params);

In this way, you could also dynamically upload the image to a file repository, get the link, and then load it as a media entity from the file repo link.

posipova
20-Turquoise
(To:done11)

The following service will create a new media, load an image from URL, and then update the newly created media with the image loaded. It can be alternated to the desired goal whether it's an immediate media assignment or updating the existing one.

var params = {

  name: "NewMediaEntity" /* STRING */,

    content: undefined /* IMAGE */

};

// no return

Resources["EntityServices"].CreateMediaEntity(params);

var params = {

  url:  'https://pbs.twimg.com/profile_images/447374371917922304/P4BzupWu.jpeg' /* STRING */,

};

// result: IMAGE

var image = Resources["ContentLoaderFunctions"].LoadImage(params);

var params = {

  name: 'NewMediaEntity'/* STRING */,

  content: image

};

// no return

Resources["EntityServices"].UpdateMediaEntity(params);

Top Tags