Execute asset upload

Upload an asset from Orange Logic to an external service

ExecuteAssetUpload: function (_sURL, _oRequest, _fCallbackSuccess, _fCallBackFail)

Request parameter attributes

AttributeTypeDescriptionRequired
_sURLstringThe URL of the external service to which assets will be sent.
Example: ${ExternalService.Config.BaseUrl} + /items/${itemID} + /versions + ?metadata=\ + encodedMetadata
yes
_oRequestobjectAn object containing the request configuration. See Request object properties below.yes
_fCallbackSuccessfunctionA callback function invoked when the upload succeeds. Receives the response as its argument.no
_fCallBackFailfunctionA callback function invoked when the upload fails. Receives the response as its argument.no

Request object properties

These properties are set on the _oRequest object.

PropertyTypeDescriptionRequired
MethodstringThe HTTP call method (GET, POST, etc.). Refer to Mozilla's documentation for a full list of method options.yes
DORecordIDstringThe record ID of an asset.yes
FormatstringThe asset format.yes
ParameterNamestringThe key of the key-value pair in which the asset is the value. For example, if the service uploading the file expects a key-value pair of "file:{fileName}", enter "file".no
HeadersobjectHTTP headers of the API call.no
FileNamestringName of the file to be streamed. Leave empty to use the title of the asset in OrangeDAM.no
ServiceNamestringThe name of the external service the asset is being synced to. Used to prevent duplication: the upload is skipped if a record already exists for the same document and the same ServiceName.no
PathToExternalIdstringA JSONPath expression evaluated against the external service's response body to extract the identifier it assigned to the uploaded asset. For example, if the service responds with { "data": { "id": "abc123" } }, pass $.data.id to extract abc123.no

Example

The following example uploads a watermarked asset using values stored in script variables, and logs the result through the success and failure callbacks.

Utils.ExecuteAssetUpload(
  "[Variables.watermarkedPath]",
  {
    Method: "GET",
    DORecordID: "[Variables.recordId]",
    Format: "[Variables.format]"
  },
  function (_sResp) {
    Log.Warn('Executed successfully: ' + _sResp);
  },
  function (_sResp) {
    Log.Warn('Execution failed: ' + _sResp);
  }
);