How to create new content

[tab:Actions]

Requirements

 

In order to publish content within THRON the following conditions must be complied:

  • A business user must be used, and it needs the appropriate permission (it can be configured in THRON Passport) to upload new content; therefore its credentials must be used (username and password must be used to perform login and obtain a valid token); a THRON application may be used to upload content, but only through SU (also known as “sudo” or “superuser”) web service which allows it to impersonate a business user (usually the owner of the application).

  • The file to load must not exceed the maximum allowed size defined in the Platform Limits article.

  • In case you want to publish the content into a public folder you must have the permission to do so (Passport) and the proper right to write into that specific folder; you must also know the folder ID. Otherwise the content will be published exclusively within the private folder of the user who is publishing it.

 

Steps for creating a new content

 

Publishing a new content to THRON takes place starting from a physical file which extension will determine content type: video, audio, image, document; in some cases the content type may be modified, for example you might want to upload an image as a document.

Loading this physical file can be performed using the GUI of THRON Dashboard, or using its APIs. The process of creating a new content begins with the phase of file selection with the subsequent upload to THRON repository. Even though the process of content creation passes through the use of a single web service, which is the insert,  the source file can be withdrawn from multiple origins: it can be taken from a specific location (local path) using the method uploadFile, it can be uploaded using an FTP server, it may be also taken from a web resource, or directly from an S3 bucket; advantages of the different upload methods are:

  • FTP upload allows you to handle large size files upload with more reliability, or to manage simultaneous uploads. If one of these is your case, you should choose FTP upload. This upload method should not be used when performing integrations, where an approach through S3 upload is advised.
  • Web upload is useful for small files.
  • S3 upload offers the possibility to stop the upload and resume it from the same point at a later time. This method is the most suitable for integration purposes.

Once the content type has been chosen and uploaded into THRON platform or FTP server, the publishing process takes place, in order to make the content available on multiple channels.

 

Publishing verification

 

If you own a business user in THRON and you started the creation of a new content, you will be properly notified both via email and collaboration center once the publishing process has ended and content is ready to use (given the fact that you are the content’s owner). In any case it is possible to know the status of publication of the content at any time. To do that you must own the xcontentID that comes in the response to the web service used for the publication of the content type, and you will have to use it as a parameter in the web service detail of JContent class. In the response of this service the status of publication for each channel will be displayed; different status are:

  • Transcoding phase in progress: 'INGESTION_INPROGRESS', 'INGESTED', 'PACKAGED', 'PACKAGING_INPROGRESS', 'PUBLISHING_INPROGRESS' or 'PACKAGED_THUMBNAIL_INPROGRESS'
  • Error during transcoding: 'PACKAGED_ERROR', 'PACKAGED_THUMBNAIL_ERROR' or 'PUBLISHED_ERROR'
  • Channel published: 'PUBLISHED' or 'PUBLISHED_THUMBNAIL' 

The same information can be retrieved with a findByProperties on the content.

 

Enrich your content with additional information

 

At the time the content is published, some basic information are automatically filled by THRON:

  • Owner: matches the user who published the content

  • Creation date

Such information can be configured by adequately filling parameters in the body of the insert request:

  • locale: the language you want to use in order to set content's basic information.
  • name: the title of the content itself. If it is not provided, THRON will automatically assign content name by using the source file name, extension excluded.
  • description: an abstract describing the content itself, maximum 10000 characters.
  • prettyId: the identifier of the content which will be used on URLs.

 

These very same information can be set in all the available language by simply setting to true the initAllLocales parameter. 

 

Multiple content import

 

Multiple content import can be performed thanks to the scripts provided in the "Code samples" section of this article, available both on PHP and JAVA language. Please make sure you set the "silent" parameter tu true when performing such operation.


Other content-related information can be included via specific web services. Such information are represented by tags and metadata. For deeper instructions on how to enrich your content with such information you should have a look at the following articles:

 

- How to link a tag to a specific entity

- How to add new metadata within a specific tag

[/tab][tab:Code Samples] [dropdown:REST - CONTENT UPLOAD]

The uploadFile function,used to add a file to repository is located within xpackager, in the “repository” package.

In order to use it you must have a valid platform token, obtainable by logging into platform.

 

In the body of the request, minimum information to be included are:

  • clientId: compiled using the service code name (usually the company name)

  • tokenId: filled with the value obtained from the login service

  • FileSource: this field indicates the file to be loaded into storage. After the “@” character you must specify the physical path through which the file can be reached, while after "filename=" you will have to specify the name by which the file will be loaded

 

The headers that should be used for the request, which must be in POST are:

  • Content-Type: multipart / form-data

 

The url of the service is formatted according to the structure:

//[clientId]-view.thron.com/api/xpackager/resources/repository/uploadFile

Where [clientId] is the name of the service code as used for the body of the request.

In the response you will get the actual name of the file in repository, as you may have added a suffix to avoid homonyms.

The insert function, used to publish a file thus creating an effective content, is located within Xadmin in the “content” package.

In order to use it you must have a valid token platform, obtainable by logging in to the platform.

 

In the body of the request, minimum information to be included are:

  • contentType: a string the scribing the type of the content to be created: Available content types are VIDEO, AUDIO, IMAGE, OTHER, PLAYLIST, PAGELET.
  • sources: the parameter describing the origin of the content's source file. Available choices are:
    • bucket: the name of the S3 bucket used for uploading the source file.
    • filePath: the absolute path of the source file inside the S3 bucket.
    • newFileName: the desired file name to be assigned to the source file into THRON Platform without extension.
    • url: the public url of the resource.
    • newFileName: the desired file name to be assigned to the source file into THRON Platform without extension.
    • buffer: the body of the Page content itself, base64 encoded with UTF-8 charset. Maximum allowed size is 2MB.
    • mimeType: used to specify the mimeType of the buffer, usually is "text/html".
    • repo: if you wish to import a source file previously uploaded to repository with the uploadFile function. You will have to provide the repositoryFileId.
    • ftp: if you wish to import a source file previously uploaded to FTP server. You will have to provide the fileName.
    • s3: if you wish to import a source file which has been previously uploaded into an S3 bucket. You will have to provide the following information:
    • webif you wish to create a new content directly from a web resource. You will have to provide the following information:
    • raw: if you wish to create a Page content. You will have to provide the following information:

 

If you wish to create a playlist you will have to provide the following information within the playlistOpt parameter:

  • template: which is basically the type of playlist you are going to create, AUDIO VIDEO or IMAGE.
  • xcontentIds: which is the array of xcontentIds of the elements composing the new playlist.

 

Additional parameters are:

  • contentOpt: all the basic information on the content itself.
  • linkedCategoryIds: the array of category Ids into which the content has to be published upon publication.
  • silentMode: a boolean parameter which will allow you to determine wether notifications must be sent at the end of content transcoding process. This is particularly useful when you plan to make massive content import.

 

The request, which must be in POST, have the following headers:

  • Content-Type: application / json

  • X-TokenId: XXXXX (using the token obtained through the login)

 

The url of the service is formatted according to the structure:

//[clientId]-view.thron.com/api/xadmin/resources/content/insert/[clientId]

Where [clientId] is the name of the service code as used for the body of the request.

[/dropdown] [dropdown:REST - PUBLISHING VIA REPOSITORY]

{
    "param": {
        "contentType": "<insert here content type, might be IMAGE, VIDEO, AUDIO or OTHER>",
        "contentOpt": {
            "initAllLocales": false,
            "basicInfoByLocale": [{
                "locale": "<insert here content locale, e.g.: EN>",
                "name": "<insert here content title>",
                "description": "<insert here content description>",
                "prettyId": "<insert here a label for this content>"
            }],
            "linkedCategoryIds": [
                "<categoryId of the folder in which you want to publish the content>"
            ]
        },
      "sources": [{
         "repo": {
            "repositoryFileId": "<repository file Id returned by the uploadFile request>"
        }
    }],
    "silentMode": false
 }
}

[/dropdown]

[dropdown:REST - PUBLISHING VIA FTP]

{
    "param": {
        "contentType": "<insert here content type, might be IMAGE, VIDEO, AUDIO or OTHER>",
        "contentOpt": {
            "initAllLocales": false,
            "basicInfoByLocale": [{
                "locale": "<insert here the locale, e.g.: EN>",
                "name": "<insert here content title>",
                "description": "<insert here content description>",
                "prettyId": "<insert here a label for this content>"
            }],
            "linkedCategoryIds": [
                "<categoryId of the folder in which you want to publish the content>"
            ]
     },
      "sources": [{
          "ftp": {
            "fileName": "<file name in the dedicated FTP area>"
        }
    }]
}, "silentMode": false
}

[/dropdown]

[dropdown:REST - PUBLISHING VIA S3]

At this link you can find an archive containing the AWS libraries to perform an upload towards an S3 bucket and a php sample which can be filled with some parameters in order to perform the upload. The same archive can be found in the attachments of this article.

In the response of the php you will obtain the URL and the request body of the insert web service which can be used in order to create the content in THRON.

The parameters which have to be filled in the php (uploadFileS3Token.php) are:

  • $strKey: to be filled with the response body of the getS3UploadCredentials request, put the whole JSON in a single line;
  • $pathFile: the whole path of the file to be uploaded;
  • $keyname=$arJsonCre->path.: the file name including extension;
  • $contentTypeFile: the mimetype, which is the file type to be uploaded (you can find a full list here);
  • $nameFileToTHRON: the title to be assigned to the content in THRON;
  • $authorFileToTHRON: the full name of the content's author;
  • $typeFileToTHRON: the THRON's content type (IMAGE, AUDIO, VIDEO, OTHER, etc.);
  • $clientIDToTHRON: your clientId;

 

[/dropdown]

[dropdown:REST - PUBLISHING VIA WEB]

{
    "param": {
        "contentType": "<insert content type, might be IMAGE, VIDEO, AUDIO or OTHER>",
        "contentOpt": {
            "initAllLocales": false,
            "basicInfoByLocale": [{
                "locale": "<insert the locale , e.g.: EN>",
                "name": "<insert content title>",
                "description": "<insert content description>",
                "prettyId": "<insert a label for this content>"
            }],
            "linkedCategoryIds": [
                "<categoryId of the folder in which you want to publish the content>"
            ]
    },
    "sources": [{
        "web": {
            "url": "<url of the file to be uploaded>",
            "newFileName": "<name to be assigned to the file in the THRON repository>"
        }
    }],
    "silentMode": false
 }
}

[/dropdown]

[dropdown:REST - PUBLISHING A PAGE]

{
    "param": {
        "contentType": "PAGELET",
        "contentOpt": {
            "initAllLocales": false,
            "basicInfoByLocale": [{
                "locale": "<insert the locale, e.g.: EN >",
                "name": "<insert content title>",
                "description": "<insert content description>",
                "prettyId": "<insert a label for this content>"
            }],
            "linkedCategoryIds": [
                "<categoryId of the folder in which you want to publish the content>"
            ]
    },
    "sources": [{
        "raw": {
            "buffer": "<insert the body of the page, base64 encoded>",
            "mimeType": "text/html"
        }
    }],
    "silentMode": false
 }
}

[/dropdown]

 

Multiple content import

The following scripts can be used to perform multiple content import into THRON, these samples are commented and can be configured at will according to the content type and the source of the files. Please remind that "silent" parameter must be set to true.

[dropdown:JAVA - MULTIPLE CONTENT IMPORT]

import it.newvision.nvp.xadmin.model.MEContentType;
import it.newvision.nvp.xadmin.services.model.content.MResponsePublishContents;
import it.newvision.nvp.xadmin.services.model.request.MContentinsertReq;
import it.newvision.nvp.xadmin.services.model.content.MPublishParams;
import it.newvision.nvp.xadmin.services.model.content.MContentOpt;
import it.newvision.nvp.xadmin.services.rest.JContentClient;
import it.newvision.nvp.xadmin.services.model.content.MContentBasicInfo;
import org.codehaus.jackson.map.ObjectMapper;
import it.newvision.nvp.xadmin.services.model.content.MSourceOpt;
import it.newvision.nvp.xadmin.services.model.content.MSourceFtpOpt;

import java.util.*;
/**
 * #################################################################################### 
 * @author stefano.bisello
 * @copyright 2016
 * ####################################################################################
 *
 * INFO
 * How to create new content
 * WebService THRON:  https://developer.thron.com/#!/content/insert
 *
 */
public class contentInsert {

 public static void main(String[] args) {

  /*SETUP FILE*/
  String clientId = "CLIENT THRON";
  String tokenID = "TOKENID";
  boolean initAllLocales = true; // init all locale content
  String contentLocale = "IT"; //content locale info
  String contentOwner = "NAME OWNER CONTENT"; //content owner
  MEContentType typeContent = MEContentType.IMAGE; //type of content (ex IMAGE.OTHER.VIDEO.AUDIO ...)
  List linkContentToCategory = Arrays.asList("IDCATEGORY THRON 1", "IDCATEGORY THRON 2", "..."); //link content to THRON category
  boolean silentMode = true; // disable notifications
  // List file present in THRON FTP
  String[] arrayFileFromFTP = {
   "IMAGE 1",
   "IMAGE 2",
   "IMAGE 3",
   "IMAGE 4",
   "IMAGE 5",
   "IMAGE 6",
   "IMAGE 7",
   "IMAGE 8",
   "IMAGE 9",
   "..."
  };
  // MAIN
  //init object for output
  ObjectMapper mapper = new ObjectMapper();
  //define request THRON
  JContentClient contentClient = new JContentClient("http://" + clientId + "-view.thron.com/api/xadmin/resources");

  //execute request
  try {
   for (int x = 0; x < arrayFileFromFTP.length; x = x + 1) {
    // pause 1 second
    Thread.sleep(1000);
    //generate request param
    MContentinsertReq newContentData = new MContentinsertReq();
    MPublishParams contentParam = new MPublishParams();
    MContentOpt contentOpt = new MContentOpt();
    List contentBasicInfo = new ArrayList();
    List sourceOpt = new ArrayList();

    MSourceFtpOpt sourceFtpOpt = new MSourceFtpOpt();
    //set content type
    contentParam.setContentType(typeContent);
    //set content Opt initAllLocales
    contentOpt.setInitAllLocales(initAllLocales);
    // set link categories
    contentOpt.setLinkedCategoryIds(linkContentToCatogory);
    //set owner
    contentOpt.setOwner(contentOwner);
    //content info (name,description,locale)
    contentBasicInfo.add(new MContentBasicInfo());
    contentBasicInfo.get(0).setDescription(" new file" + arrayFileFromFTP[x]);
    contentBasicInfo.get(0).setLocale(contentLocale);
    contentBasicInfo.get(0).setName(arrayFileFromFTP[x]);
    contentOpt.setBasicInfoByLocale(contentBasicInfo);
    contentParam.setContentOpt(contentOpt);
    //file source
    sourceOpt.add(new MSourceOpt());
    sourceFtpOpt.setFileName(arrayFileFromFTP[x]);
    sourceOpt.get(0).setFtp(sourceFtpOpt);
    contentParam.setSources(sourceOpt);
    //add param
    newContentData.setParam(contentParam);
    //set SilentMode
    newContentData.setSilentMode(silentMode);
    // System.out.println(mapper.writeValueAsString(newContentData));
    // add content to THRON from request
    MResponsePublishContents ris = contentClient.insert(tokenID, clientId, newContentData, null);
    //RESULT THRON OUTPUT
    System.out.println(mapper.writeValueAsString(ris));
   }

  } catch (Exception e) {
   //error THRON OUTPUT
   System.out.println(e);
  }
 }
}

[/dropdown] [dropdown:PHP - MULTIPLE CONTENT IMPORT]

<?php
/**
 * ####################################################################################
 * @author stefano.bisello
 * @copyright 2016
 * ####################################################################################
 *
 * INFO
 * How to create new content
 * WebService THRON:  https://developer.thron.com/#!/content/insert
 *
 * ####################################################################################
 * config
 * ####################################################################################
 */
/*SETUP FILE*/
set_time_limit(3620);

// client

$client_idTHRON = 'CLIENT THRON';

// TOKEN THRON

$tokenID = 'TOKENID';

// ID THRON

$initAllLocales = "true"; // init all locale content
$contentLocale = "IT"; //content locale info
$contentOwner = "NAME OWNER CONTENT"; //content owner
$linkContentToCatogory = array(
    "IDCATEGORY THRON 1",
    "IDCATEGORY THRON 2",
    "..."
); //link content to THRON category
$silentMode = true; // disable notifications
$contentType = "IMAGE"; //(ex IMAGE.OTHER.VIDEO.AUDIO ...)

// List file present in THRON FTP

$arrayFileFromFTP = array(
    "IMAGE 1",
    "IMAGE 2",
    "IMAGE 3",
    "..."
);

// #########################################################################################
// UTILITY
// #########################################################################################
// insert content to THRON

function insertContentTHRON($client_id, $tokend, $bodyRequest)
    {

    // configure request webService THRON

    $url = "http://" . $client_id . "-view.thron.com/api/xadmin/resources/content/insert/" . $client_id;

    // header  request webService THRON

    $header = array(
        "Content-Type: application/json",
        "X-TOKENID:" . $tokend
    );

    // request THRON

    $request = json_encode($bodyRequest);

    // configure curl

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
    $curlRes = curl_exec($curl);
    $curlResInfo = curl_getinfo($curl);
    curl_close($curl);

    // parse response

    $resHeadersString = substr($curlRes, 0, $curlResInfo['header_size']);
    $resBody = substr($curlRes, $curlResInfo['header_size']);
    $response = json_decode($resBody, true);

    // print_r($resBody);

    return $response;
    }

// #########################################################################################
// main
// #########################################################################################
// array response insert

$risInsert = array();

// insert content to THRON Platform

for ($i = 0; $i < count($arrayFileFromFTP); $i++)
    {

    // generate body request

    $bodyRequest = array(
        "param" => array(
            "contentType" => $contentType,
            "contentOpt" => array(
                "initAllLocales" => $initAllLocales,
                "basicInfoByLocale" => array(
                    array(
                        "locale" => $contentLocale,
                        "name" => $arrayFileFromFTP[$i],
                        "description" => "new file:" . $arrayFileFromFTP[$i]
                    )
                ) ,
                "owner" => $contentOwner,
                "linkedCategoryIds" => $linkContentToCatogory
            ) ,
            "sources" => array(
                array(
                    "ftp" => array(
                        "fileName" => $arrayFileFromFTP[$i]
                    )
                )
            ) ,
        ) ,
        "silentMode" => $silentMode
    );

    // execute request

    $risInsert[] = insertContentTHRON($client_idTHRON, $tokenID, $bodyRequest);
    }

[/dropdown]

[/tab]

Was this article helpful?
0 out of 0 found this helpful

Have more questions?

SUBMIT A REQUEST

Hai altre domande?

INOLTRA UNA RICHIESTA

Comments

  • Avatar
    Antonio Comelli

    We have updated this article by including JAVA and PHP samples which can be used to perform multiple content imports.