Adobe PDF Services #ASSET: メタデータ取得

Adobe PDF Services #ASSET: メタデータ取得

Adobe PDF Services #ASSET: メタデータ取得

translate Adobe PDF Services #ASSET: Get Metadata

PDF Services 用の内部ストレージに保存されている ASSET(各種素材ファイル)について、そのメタデータを取得します。具体的には、アクセス可能なユーザID、ファイルサイズ、Content-Type を取得します。

Auto Step icon
Configs for this Auto Step
AuthzConfU1
U1: PDF-SERVICES-API Client ID 設定を選択してください(認証設定>直接指定) *
AuthzConfU2
U2: PDF-SERVICES-API Client Secret 設定を選択してください(認証設定>直接指定) *
StrConfA1
A1: AssetID をセットしてください *#{EL}
SelectConfB1
B1: アクセス可能なユーザID(or 技術アカウント)が格納される文字列型データ項目を選択してください (更新)
SelectConfB2
B2: AssetファイルのByteサイズが格納される数値型データ項目を選択してください (更新)
SelectConfB3
B3: AssetファイルのContent-Typeが格納される文字列型データ項目を選択してください (更新)
StrConfU3
U3: 指定リージョンで処理させたい場合 {regionCode} をセットしてください(”ew1″)#{EL}
Script (click to open)
// GraalJS standard mode Script Script (engine type: 3)
// cf. 'engine type: 2': "GraalJS Nashorn compatible mode" (renamed from "GraalJS" at 20230526)

//////// START "main()" /////////////////////////////////////////////////////////////////

main();
function main(){ 

////// == Config Retrieving / 工程コンフィグの参照 ==
const strAuthzId          = configs.get( "AuthzConfU1" );       /// REQUIRED
  engine.log( " AutomatedTask Config: Authz ID: " + strAuthzId );
  const strClientId       = httpClient.getOAuth2Token( strAuthzId );
  if (  strClientId     === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {U1: ClientId} is empty \n" );
  }
const strAuthzSecret      = configs.get( "AuthzConfU2" );       /// REQUIRED
  engine.log( " AutomatedTask Config: Authz SECRET: " + strAuthzSecret );
  const strClientSecret   = httpClient.getOAuth2Token( strAuthzSecret );
  if (  strClientSecret === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {U2: ClientSecret} is empty \n" );
  }
const strRegionCode       = configs.get( "StrConfU3" );         // Not Required
  let strRegionPostfix    = strRegionCode !== "" ? ("-" + strRegionCode) : "";
  engine.log( " AutomatedTask Config: strRegionPostfix: " + strRegionPostfix );
  // https://developer.adobe.com/document-services/docs/overview/pdf-services-api/howtos/service-region-configuration-for-apis/
const strAssetId          = configs.get( "StrConfA1" );         /// REQUIRED
const strPocketUserId      = configs.getObject( "SelectConfB1" );  // Not Required
const numPocketSize        = configs.getObject( "SelectConfB2" );  // Not Required
const strPocketContentType = configs.getObject( "SelectConfB3" );  // Not Required



////// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)



////// == Calculating / 演算 ==

//// Adobe Developer > PDF Services API > Generate Token
//// Generate access token to perform PDF Services operations
//// https://developer.adobe.com/document-services/docs/apis/#tag/Generate-Token

/// prepare request1
let request1Uri = "https://pdf-services" + strRegionPostfix + ".adobe.io/token";
let request1 = httpClient.begin(); // HttpRequestWrapper
/// prepare application/x-www-form-urlencoded
    request1 = request1.formParam ( "client_id",     strClientId );
    request1 = request1.formParam ( "client_secret", strClientSecret );

/// try request1
const response1     = request1.post( request1Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest1 Start: " + request1Uri );
const response1Code = response1.getStatusCode() + ""; // JavaNum to string
const response1Body = response1.getResponseAsString();
engine.log( " AutomatedTask ApiResponse1 Status: " + response1Code );
if( response1Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response1Code + "\n" + response1Body + "\n" );
}
/* engine.log( response1Body ); // debug
{
  "access_token":"xxxxxxxxxx975yyyyyyyyyy",
  "token_type":"bearer",
  "expires_in":86399
}
*/

/// parse response1 (OAuth Server-to-Server)
const response1Obj = JSON.parse( response1Body );
const strAccessToken = response1Obj.access_token;


//// Adobe Developer > PDF Services API > Assets
//// Get asset metadata.
//// https://developer.adobe.com/document-services/docs/apis/#tag/Assets/operation/asset.metadata

/// prepare request2
let request2Uri = "https://pdf-services" + strRegionPostfix + ".adobe.io/assets/" +
                   strAssetId + "/metadata";
let request2 = httpClient.begin(); // HttpRequestWrapper
/// prepare header parameters
    request2 = request2.bearer ( strAccessToken );
    request2 = request2.header ( "x-api-key", strClientId );

/// try request2
const response2     = request2.get ( request2Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest2 Start: " + request2Uri );
const response2Code = response2.getStatusCode() + ""; // JavaNum to string
const response2Body = response2.getResponseAsString();
engine.log( " AutomatedTask ApiResponse2 Status: " + response2Code );
if( response2Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response2Code + "\n" + response2Body + "\n" );
}
/* engine.log( response2Body ); // debug
{
  "entity":"xxxxxyyyyyzzzzzwwwwwXXXX@techacct.adobe.com",
  "type":"image/jpeg",
  "size":1408073
}
*/

/// parse response2 (Upload URI)
const response2Obj = JSON.parse( response2Body );
const strUserId    = response2Obj.entity;
const numSize      = response2Obj.size;
const strContentType = response2Obj.type;



////// == Data Updating / ワークフローデータへの代入 ==

if( strPocketUserId !== null ){
  engine.setData( strPocketUserId, strUserId );
}
if( numPocketSize !== null ){
  engine.setData( numPocketSize, new java.math.BigDecimal( numSize ) );
}
if( strPocketContentType !== null ){
  engine.setData( strPocketContentType, strContentType );
}

} //////// END "main()" /////////////////////////////////////////////////////////////////


/*
Notes:
- If you place this "Automated Step" in the Workflow diagram, the request will be automatically sent every time the process token arrives.
    - A request is automatically sent to the Adobe PDF Services API server. (REST API)
    - The response from the Adobe PDF Services API server is automatically parsed.
- This "Automated Step" will automatically retrieve metadata for the file (Asset) stored in Adobe's internal storage.
    - Accessible entity: User ID or Technical Account ID
    - Size of the file (Asset) in Byte
    - Content-Type of the file (Asset)
- To activate a Workflow App that includes this Automated Step, "HTTP Authz Setting" is required
    - Set Credentials to "Token Fixed Value" in Workflow App.
    - Obtain Credentials ("Client ID" and "Client Secret") in advance.
        - https://acrobatservices.adobe.com/dc-integration-creation-app-cdn/main.html?api=pdf-services-api
    - Adobe Developer Console
        - https://developer.adobe.com/console/projects

APPENDIX
- PDF Services: 
    - Essential PDF tools to store and share files online, as well as create, combine, export, organize, and fill & sign documents.
    - https://helpx.adobe.com/enterprise/using/optional-services.html
- PDF Services API to automate for your document workflows
    - create a PDF from a dynamic HTML report
    - set a password to prevent unauthorized opening of the document
    - compress it for sharing as an attachment
    - extract text, tables, images and document structure to enable downstream solutions
    - https://developer.adobe.com/document-services/docs/overview/#pdf-services-api-to-automate-for-your-document-workflows
- Adobe PDF Services API Free Tier
    - 500 freeDocument Transactions per month. No credit card required. (asof 202306)
    - https://developer.adobe.com/document-services/docs/overview/limits/#usage-limits
- Internal storage retention period
    - Each ASSET is deleted after a certain period of time.
    - AutomatedTask UnexpectedResponseError: 404
    - `{"error":{"code":"Not Found","message":"The requested resource does not exist."}}`

Notes-ja:
- この[自動工程]をワークフロー図に配置すれば、案件が到達する度にリクエストが自動送信されます。
    - Adobe PDF Services API サーバに対してリクエストが自動送出されます。(REST API通信)
    - Adobe PDF Services API サーバからのレスポンスが自動保存解析されます。
- この[自動工程]は、Adobe 内部ストレージに保存されているファイル(Asset)のメタデータを自動取得します。
    - アクセス可能な実体(エンティティ):User ID もしくは Technical Account ID
    - 素材ファイル(Asset)のサイズ(Byte)
    - 素材ファイル(Asset)の Content-Type
- この[アドオン自動工程]を含むワークフローアプリを運用するには[HTTP 認証設定]が必要です。
    - Credentials はワークフローアプリの[トークン直接指定]にセットします。
    - あらかじめ Credentials ("Client ID" および "Client Secret") を取得しておいてください。
        - https://acrobatservices.adobe.com/dc-integration-creation-app-cdn/main.html?api=pdf-services-api
    - Adobe Developer Console
        - https://developer.adobe.com/console/projects

APPENDIX-ja
- PDF Servicesとは
    - ファイルのオンラインでの保存、共有のほか、ドキュメントの作成、結合、書き出し、整理、入力と署名を行うための PDF 基本ツールです。
    - https://helpx.adobe.com/jp/enterprise/using/optional-services.html
- Document ワークフローを自動化する PDF Services API
    - 動的 HTML レポートから PDF を簡単に作成
    - ドキュメントが不正に開かれないようにパスワードを設定
    - 添付ファイルとして共有するために圧縮
    - テキスト、表、画像、ドキュメント構造を抽出してダウンストリーム ソリューションを実現
    - https://developer.adobe.com/document-services/docs/overview/#pdf-services-api-to-automate-for-your-document-workflows
- Adobe PDF Services API の無料利用枠
    - 毎月500件の無料ドキュメントトランザクション。クレジットカードは必要なし。(202306現在)
    - https://developer.adobe.com/document-services/docs/overview/limits/#usage-limits
- 内部ストレージの保存期間
    - 各ASSETは、一定時間経過で削除されます。
    - AutomatedTask UnexpectedResponseError: 404
    - `{"error":{"code":"Not Found","message":"The requested resource does not exist."}}`
*/

Download

warning 自由改変可能な JavaScript (ECMAScript) コードです。いかなる保証もありません。
(アドオン自動工程のインストールは Professional editionでのみ可能です)

Notes

  • この[自動工程]をワークフロー図に配置すれば、案件が到達する度にリクエストが自動送信されます。
    • Adobe PDF Services API サーバに対してリクエストが自動送出されます。(REST API通信)
    • Adobe PDF Services API サーバからのレスポンスが自動保存解析されます。
  • この[自動工程]は、Adobe 内部ストレージに保存されているファイル(Asset)のメタデータを自動取得します。
    • アクセス可能な実体(エンティティ):User ID もしくは Technical Account ID
    • 素材ファイル(Asset)のサイズ(Byte)
    • 素材ファイル(Asset)の Content-Type
  • この[アドオン自動工程]を含むワークフローアプリを運用するには[HTTP 認証設定]が必要です。

Capture

PDF Services 用の内部ストレージに保存されている ASSET(各種素材ファイル)について、そのメタデータを取得します。具体的には、アクセス可能なユーザID、ファイルサイズ、Content-Type を取得します。

Appendix

See Also

Adobe PDF Services #ASSET: アップロード

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

Questetra Supportをもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む

上部へスクロール