自定义应用程序的内部结构 how-custom-application-works

使用下图了解在客户端使用自定义应用程序处理数字资产时的端到端工作流程。

自定义应用程序工作流

图:使用AdobeAsset Compute Service. ​处理资源时涉及的步骤

注册 registration

客户端必须在第一次向/process发出请求之前调用/register一次,以便设置和检索日志URL以接收AdobeAsset compute的AdobeI/O Events事件。

curl -X POST \
  https://asset-compute.adobe.io/register \
  -H "x-ims-org-id: $ORG_ID" \
  -H "x-gw-ims-org-id: $ORG_ID" \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -H "x-api-key: $API_KEY"

@adobe/asset-compute-client JavaScript库可以在NodeJS应用程序中使用,以处理从注册、处理到异步事件处理的所有必要步骤。 有关所需标头的详细信息,请参阅身份验证和授权

正在处理 processing

客户端发送了处理请求。

curl -X POST \
  https://asset-compute.adobe.io/process \
  -H "x-ims-org-id: $ORG_ID" \
  -H "x-gw-ims-org-id: $ORG_ID" \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -H "x-api-key: $API_KEY" \
  -d "<RENDITION_JSON>

客户端负责使用预签名URL正确设置演绎版格式。 可在NodeJS应用程序中使用@adobe/node-cloud-blobstore-wrapper JavaScript库对URL进行预签名。 目前,该库仅支持Azure Blob Storage和AWS S3容器。

处理请求返回可用于轮询Adobe I/O事件的requestId

下面是一个自定义应用程序处理请求示例。

{
    "source": "https://www.adobe.com/some-source-file.jpg",
    "renditions" : [
        {
            "worker": "https://my-project-namespace.adobeioruntime.net/api/v1/web/my-namespace-version/my-worker",
            "name": "rendition1.jpg",
            "target": "https://some-presigned-put-url-for-rendition1.jpg",
        }
    ],
    "userData": {
        "my-asset-id": "1234567890"
    }
}

Asset Compute Service将自定义应用程序演绎版请求发送到自定义应用程序。 它使用HTTPPOST访问提供的应用程序URL,该URL是来自App Builder的安全Web操作URL。 所有请求都使用HTTPS协议来最大限度地提高数据安全性。

自定义应用程序使用的Asset computeSDK处理HTTPPOST请求。 它还处理源下载、上传演绎版、发送AdobeI/O Events和错误处理。

应用程序代码 application-code

自定义代码只需提供回调即可获取本地可用的源文件(source.path)。 rendition.path是放置资产处理请求的最终结果的位置。 自定义应用程序使用回调将本地可用的源文件转换为使用传入的名称(rendition.path)的格式副本文件。 自定义应用程序必须写入rendition.path才能创建演绎版:

const { worker } = require('@adobe/asset-compute-sdk');
const fs = require('fs').promises;

// worker() is the entry point in the SDK "framework".
// The asynchronous function defined is the rendition callback.
exports.main = worker(async (source, rendition) => {

    // Tip: custom worker parameters are available in rendition.instructions.
    console.log(rendition.instructions.name); // should print out `rendition.jpg`.

    // Simplest example: copy the source file to the rendition file destination so as to transfer the asset as is without processing.
    await fs.copyFile(source.path, rendition.path);
});

下载源文件 download-source

自定义应用程序仅处理本地文件。 Asset computeSDK处理源文件的下载。

创建演绎版 rendition-creation

SDK为每个节目调用异步节目回调函数

回调函数具有对解释对象的访问权限。 source.path已存在,是源文件的本地副本的路径。 rendition.path是必须存储已处理演绎版的路径。 除非设置了disableSourceDownload标志,否则应用程序必须完全使用rendition.path。 否则,SDK将无法找到或识别演绎版文件,并将失败。

通过对示例的过度简化,说明了自定义应用程序的剖析。 应用程序只会将源文件复制到节目目标。

有关演绎版回调参数的更多信息,请参阅Asset computeSDK API

上传节目 upload-rendition

在每个演绎版创建并存储在rendition.path提供的路径的文件中后,Asset computeSDK会将每个演绎版上传到云存储(AWS或Azure)。 当且仅当传入请求具有多个指向同一应用程序URL的演绎版时,自定义应用程序才会同时获取多个演绎版。 上传到云存储是在每个演绎版之后并为下一个演绎版运行回调之前完成的。

batchWorker()具有不同的行为。 它会处理所有演绎版,并且只有在处理完所有演绎版后,才会上传它们。

Adobe I/O个事件 aio-events

SDK为每个呈现版本发送AdobeI/O Events。 这些事件的类型是rendition_createdrendition_failed,具体取决于结果。 有关详细信息,请参阅Asset compute异步事件

接收Adobe I/O个事件 receive-aio-events

客户端根据其使用逻辑轮询AdobeI/O Events日志。 初始日记账URL是/register API响应中提供的URL。 可以使用事件中存在的requestId识别事件,该值与在/process中返回的相同。 每个演绎版都有一个单独的事件,在上传(或失败)演绎版后立即发送该事件。 当客户端收到匹配事件时,可以显示或以其他方式处理生成的演绎版。

JavaScript库asset-compute-client使用waitActivation()方法简化日志轮询以获取所有事件。

const events = await assetCompute.waitActivation(requestId);
await Promise.all(events.map(event => {
    if (event.type === "rendition_created") {
        // get rendition from cloud storage location
    }
    else if (event.type === "rendition_failed") {
        // failed to process
    }
    else {
        // other event types
        // (could be added in the future)
    }
}));

有关如何获取日志事件的详细信息,请参阅AdobeI/O Events API

recommendation-more-help
b027be24-3772-44c0-a56d-a4ba23dcb50b