應用程式程式碼

自訂程式碼只需要提供取用本機可用原始程式檔(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.path已經存在,而且是來源檔案的本機復本路徑。 rendition.path是必須儲存已處理轉譯的路徑。 除非已設定disableSourceDownload旗標,否則應用程式必須完全使用rendition.path。 否則,SDK將無法找到或識別轉譯檔案,並會失敗。

範例的過度簡化是為了說明和專注於自訂應用程式的剖析。 應用程式只會將來源檔案複製到轉譯目的地。

如需有關轉譯回呼引數的詳細資訊,請參閱Asset computeSDK API

上傳轉譯

在建立每個轉譯並儲存在rendition.path提供路徑的檔案中後,Asset computeSDK會將每個轉譯上傳至雲端儲存空間(AWS或Azure)。 若且唯若傳入請求具有多個指向相同應用程式URL的轉譯時,自訂應用程式才會同時取得多個轉譯。 上傳至雲端儲存空間會在每個轉譯之後以及下一個轉譯的執行回呼之前完成。

batchWorker()有不同的行為。 它會處理所有轉譯,並在所有轉譯均已處理完畢後上傳它們。