Google Drive Upload

Uploads the file specified by File type data item to the specified directory of Google Drive, and stores its communication log in a String type data item

    A. Set OAuth2 Config Name (at [OAuth 2.0 Setting])Single-line inputRequired
    B. Select STRING/SELECT for Folder ID (Non-existent Error)Data selectString(single line)orSelect(radio/select/search)Required
    C. Select FILE DATA for UploadData selectFileRequired
    X. Select STRING DATA for Access Log (update)Data selectString(multiple line)
    -variable namevariable label
    Aconf_OAuth2Set OAuth2 Config Name (at [OAuth 2.0 Setting])
    Bconf_DataIdBSelect STRING/SELECT for Folder ID (Non-existent Error)
    Cconf_DataIdCSelect FILE DATA for Upload
    Xconf_DataIdXSelect STRING DATA for Access Log (update)
    // Upload to Google Drive via Drive APIs v3 (ver. 20161019)
    // (c) 2016, Questetra, Inc. (the MIT License)
    
    //// == 工程コンフィグの参照 / Config Retrieving ==
    var oauth2 = configs.get( "conf_OAuth2" );
    var dataIdB = configs.get( "conf_DataIdB" ); // (returns Number)
    var dataIdC = configs.get( "conf_DataIdC" ); // (returns Number)
    var dataIdX = configs.get( "conf_DataIdX" ); // (returns Number)
    
    //// == ワークフローデータの参照 / Data Retrieving ==
    var folderId = "";
    if( data.get( dataIdB ) instanceof java.util.ArrayList ){
      folderId = data.get( dataIdB ).get(0).getValue() + "";
    }else if( data.get( dataIdB ) instanceof java.lang.String ){
      folderId = data.get( dataIdB ) + "";
    }
    var files = data.get( dataIdC );
    
    //// == 演算 / Calculating ==
    var accessLog = "";
    var token = httpClient.getOAuth2Token( oauth2 );
    
    for( var i = 0; i < files.size(); i++  ){
      var uri = "https://www.googleapis.com/upload/drive/v3/files?uploadType=media";
      var response = httpClient.begin()
        .bearer( token )
        .body( files.get(i) )
        .post( uri );
      accessLog += "---POST request--- " + response.getStatusCode() + "\n";
      accessLog += response.getResponseAsString() + "\n";
    
      var jsonObj = JSON.parse( response.getResponseAsString() );
      var uri2 = "https://www.googleapis.com/drive/v3/files/";
      uri2 += jsonObj.id;
      var myObj2 = {};
      myObj2.name = files.get(i).getName() + "";
      var response2 = httpClient.begin()
        .bearer( token )
        .queryParam( "addParents", folderId )
        .queryParam( "removeParents", "root" )
        .body( JSON.stringify( myObj2 ), "application/json" )
        .patch( uri2 );
      accessLog += "---PATCH request--- " + response2.getStatusCode() + "\n";
      accessLog += response2.getResponseAsString() + "\n";
    }
    
    //// == ワークフローデータへの代入 / Data Updating ==
    if( dataIdX !== "" ){
      retVal.put( dataIdX, accessLog );
    }
    

    • B’: Google Drive folder ID stored in the Data Item selected at config B*
    • C’: File stored in the Data Item selected at config C
    • File group C’ will be uploaded to the specified directory B’
    • Communication log will be stored in the Data Item selected at config X
    • G Suite Users should consider about using [Service Task (Google Drive)] (M229)
    • It requires registration of Project at Google API Manager in advance
    • If specified folder ID does not exist, it results in an error
      If there are filename conflicts, multiple files with same filename will be saved
    • * https://drive.google.com/drive/folders/0BexampleEXAMPLEexampledvamc