通过下图,可了解当客户使用自定义应用程序处理数字资产时的端对端工作流程。
图:使用处理资产时涉及的步 Asset Compute Service骤。
客户端必须在向/process
发出第一个请求之前调用/register
一次,以设置并检索日志URL,以接收Adobe I/O事件以进行AdobeAsset compute。
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应用程序中使用,以处理从注册、处理到异步事件处理等所有必需步骤。 有关所需标头的更多信息,请参阅Authentication and Authorization。
客户端发送一个正在处理的请求。
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正确设置演绎版的格式。 @adobe/node-cloud-blobstore-wrapper
JavaScript库可在NodeJS应用程序中用于预签URL。 目前,库仅支持Azure Blob Storage和AWS S3容器。
处理请求返回一个requestId
,可用于轮询Adobe I/O事件。
下面是自定义应用程序处理请求的示例。
{
"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将自定义应用程序呈现请求发送到自定义应用程序。 它对提供的应用程序URL使用HTTPPOST,该URL是Project Firefly提供的安全Web操作URL。 所有请求都使用HTTPS协议来最大限度地提高数据安全性。
自定义应用程序使用的Asset computeSDK可处理HTTPPOST请求。 它还可处理源的下载、上传演绎版、发送Adobe I/O事件和错误处理。
自定义代码只需提供一个回调即可获取本地可用的源文件(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);
});
自定义应用程序仅处理本地文件。 下载源文件由Asset computeSDK处理。
SDK会为每个演绎版调用异步演绎版回调函数。
回调函数对source和rendition对象具有访问权限。 source.path
已存在,是源文件的本地副本的路径。 rendition.path
是必须存储已处理的再现的路径。 除非设置了disableSourceDownload标志,否则应用程序必须完全使用rendition.path
。 否则,SDK无法找到或识别呈现版本文件,并且失败。
该示例的过度简化是为了说明和重点介绍自定义应用程序的结构。 应用程序只会将源文件复制到演绎版目标。
有关演绎版回调参数的更多信息,请参阅Asset computeSDK API。
创建每个呈现版本并将其存储在具有rendition.path
提供路径的文件中后,Asset computeSDK会将每个呈现版本上传到云存储(AWS或Azure)。 当且仅当传入请求具有指向同一应用程序URL的多个演绎版时,自定义应用程序才会同时获取多个演绎版。 将上传到云存储的操作在每个演绎版之后,并在为下一个演绎版运行回调之前完成。
batchWorker()
的行为不同,因为它实际上会处理所有演绎版,并且仅在所有演绎版都经过处理后,才上传这些演绎版。
SDK会为每个演绎版发送Adobe I/O事件。 这些事件的类型为rendition_created
或rendition_failed
,具体取决于结果。 有关事件详细信息,请参阅Asset compute异步事件。
客户端根据其使用逻辑轮询Adobe I/O 事件日志。 初始日志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)
}
}));
有关如何获取日志事件的详细信息,请参阅Adobe I/O 事件API。