Google ドライブ: ファイル, コピー
Google ドライブ: ファイル, コピー (Google Drive: File, Copy)
Googleドライブ内でファイルのコピーを新規保存します。任意の名前での保存にも対応しています。ファイル名は、必ずしもフォルダ内で一意である必要はありません。
Configs
  • U: HTTP認証設定を選択してください *
  • A1: コピー元ファイルID(FILE-ID)をセットしてください *#{EL}
  • B1: 新ファイルが保存されるDriveフォルダのIDをセットしてください#{EL}
  • B2: 新ファイルを別名で保存したい場合、ファイル名をセットしてください#{EL}
  • C1: 新ファイルのファイル名が格納される文字列型データ項目を選択してください (更新)
  • C2: 新ファイルのファイルIDが格納される文字列型データ項目を選択してください (更新)
  • C3: 新ファイルの編集用URLが格納される文字列型データ項目を選択してください (更新)
  • C4: 新ファイルの閲覧用URLが格納される文字列型データ項目を選択してください (更新)
  • C5: 新ファイルのMimeTypeが格納される文字列型データ項目を選択してください (更新)
Script (click to open)
// GraalJS Script (engine type: 2)

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

main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strAuthzSetting     = configs.get      ( "AuthzConfU" );   /// REQUIRED
  engine.log( " AutomatedTask Config: Authz Setting: " + strAuthzSetting );
const strInputfileId      = configs.get      ( "StrConfA1" );    /// REQUIRED
  if( strInputfileId    === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A1: FileID} is empty \n" );
  }
const strOutputfolderId   = configs.get      ( "StrConfB1" );    // NotRequired
  if( strOutputfolderId === "" ){
    engine.log( " AutomatedTask ConfigWarning:" +
                " Config {B1: FolderId} is empty" );
  }
let   strOutputfileSaveas = configs.get      ( "StrConfB2" );    // NotRequired

const strPocketOutputfileName = configs.getObject( "SelectConfC1" ); // NotRequired
const strPocketOutputfileId   = configs.getObject( "SelectConfC2" ); // NotRequired
const strPocketOutputfileEdit = configs.getObject( "SelectConfC3" ); // NotRequired
const strPocketOutputfileView = configs.getObject( "SelectConfC4" ); // NotRequired
const strPocketOutputfileMime = configs.getObject( "SelectConfC5" ); // NotRequired

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


//// == Calculating / 演算 ==
/// Google Workspace for Developers > Google Drive for Developers > v3
/// https://developers.google.com/drive/api/v3/reference/files/copy
// request1, prepare
let request1Obj = {};
    if( strOutputfolderId !== "" ){
      request1Obj.parents     = [];
      request1Obj.parents[0]  = strOutputfolderId;
    }
    if( strOutputfileSaveas !== "" ){
      request1Obj.name        = strOutputfileSaveas;
    }
let request1Uri = "https://www.googleapis.com/drive/v3/files/" +
                  strInputfileId + "/copy";
let request1    = httpClient.begin(); // HttpRequestWrapper
    request1    = request1.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
    // https://questetra.zendesk.com/hc/en-us/articles/360024574471-R2300#HttpRequestWrapper
    request1    = request1.queryParam( "supportsAllDrives", "true" );
    request1    = request1.body( JSON.stringify( request1Obj ), "application/json" );

// request1, try
const response1     = request1.post( request1Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest1 Start: " + request1Uri );
const response1Code = response1.getStatusCode() + "";
const response1Body = response1.getResponseAsString() + "";
engine.log( " AutomatedTask ApiResponse Status: " + response1Code );
if( response1Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response1Code + "\n" + response1Body + "\n" );
}

// response1, parse
/* engine.log( response1Body ); // debug
{
  "kind": "drive#file",
  "id": "1x9rZrt-Iyj2QBewzeLF1P7fG-plXaKMyCnJSFAT-d1g",
  "name": "Questetra-Intro-en",
  "mimeType": "application/vnd.google-apps.document"
}
*/
const response1Obj = JSON.parse( response1Body );
engine.log( " AutomatedTask ApiResponse: NewFile ID: " + response1Obj.id );
engine.log( " AutomatedTask ApiResponse: MIME Type: " +  response1Obj.mimeType );


//// == Data Updating / ワークフローデータへの代入 ==
if( strPocketOutputfileName !== null ){
  engine.setData( strPocketOutputfileName, response1Obj.name );
}
if( strPocketOutputfileId   !== null ){
  engine.setData( strPocketOutputfileId,   response1Obj.id );
}
if( strPocketOutputfileEdit !== null ){
  engine.setData( strPocketOutputfileEdit, "https://docs.google.com/open?id=" +
                                            response1Obj.id );
}
if( strPocketOutputfileView !== null ){
  engine.setData( strPocketOutputfileView, "https://drive.google.com/file/d/" +
                                            response1Obj.id + "/view" );
}
if( strPocketOutputfileMime !== null ){
  engine.setData( strPocketOutputfileMime, response1Obj.mimeType );
}


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


/*
Notes:
- It is used when creating a document by duplicating the template. (Invoices, Proposals, etc.)
- Refer to the file ID of the image from the URL in "Open in new window"
- If Folder-ID not specified, the file will inherit any discoverable parents of the source file.
- This automated task (Addon) does not support to duplicate to "My Drive".
Notes-ja:
- ひな型ファイルを複製して個別文書を作成する際等に利用します。(請求書、見積書、提案書など)
- 画像ファイルのIDは「新しいウィンドウで開く」のURLを参照します。
- 保存フォルダが無指定の場合、元ファイルの所属フォルダ情報が継承されます。
- この自動工程(アドオン)では、"マイドライブ" への複製保存はできません。

APPENDIX-en
- Folders cannot be copied or converted.
- Setting example of "HTTP Authentication" (OAuth2)
    - Authorization Endpoint URL:
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - Token Endpoint URL:
        - https://accounts.google.com/o/oauth2/token
    - Scope:
        - https://www.googleapis.com/auth/drive
    - Client ID, Consumer Secret:
        - ( from https://console.developers.google.com/ )
        - Redirect URLs: https://s.questetra.net/oauth2callback
APPENDIX-ja
- フォルダはコピー(変換)できません
- "HTTP認証"(OAuth2)の設定例
    - Authorization Endpoint URL:
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - Token Endpoint URL:
        - https://accounts.google.com/o/oauth2/token
    - Scope:
        - https://www.googleapis.com/auth/drive
    - Client ID, Consumer Secret:
        - ( from https://console.developers.google.com/ )
        - Redirect URLs: https://s.questetra.net/oauth2callback
*/

Download

2021-04-19 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/google-drive-file-copy-2021/
Addonファイルのインポートは Professional でのみご利用いただけます

Notes

  • ひな型ファイルを複製して個別文書を作成する際等に利用します。(請求書、見積書、提案書など)
  • 画像ファイルのIDは「新しいウィンドウで開く」のURLを参照します。
  • 保存フォルダが無指定の場合、元ファイルの所属フォルダ情報が継承されます。
  • この自動工程(アドオン)では、”マイドライブ” への複製保存はできません。

Capture

Googleドライブ内でファイルのコピーを新規保存します。任意の名前での保存にも対応しています。ファイル名は、必ずしもフォルダ内で一意である必要はありません。
Googleドライブ内でファイルのコピーを新規保存します。任意の名前での保存にも対応しています。ファイル名は、必ずしもフォルダ内で一意である必要はありません。

Appendix

See also

コメントを残す

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

%d