Box Upload

Uploads the file specified by File type data item to the specified directory of box, 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 on box ("0" for Root)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 on box ("0" for Root)
    Cconf_DataIdCSelect FILE DATA for Upload
    Xconf_DataIdXSelect STRING DATA for Access Log (update)
    // Upload to box via boxAPI (ver. 20161018)
    // (c) 2016, Questetra, Inc. (the MIT License)
    
    // OAuth2 config
    // Authorization Endpoint URL: https://app.box.com/api/oauth2/authorize
    // Token Endpoint URL: https://app.box.com/api/oauth2/token
    // Scope: 
    // Consumer Key: (Get by box Application on box Developers)
    // Consumer Secret: (Get by box Application on box Developers)
    
    //// == 工程コンフィグの参照 / 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 responseJson = "";
    var token = httpClient.getOAuth2Token( oauth2 );
    
    if (files !== null) {
      for (var i=0; i< files.size(); i++) {
        var file = files.get(i);
        var attributes = {
          //parent : '0'
          parent : {id : folderId}
        };
        attributes["name"] = String(file.getName());
    
        var response = httpClient.begin()
          .bearer(token)
          .multipart('attributes', JSON.stringify(attributes))
          .multipart('file', file)
          .post('https://upload.box.com/api/2.0/files/content');
        accessLog += "---POST request--- " + response.getStatusCode() + "\n";
        accessLog += file.getName() + "\n";
        responseJson += response.getResponseAsString() + "\n";
        
        //if (response.getStatusCode() !== 201) {
        //  throw "failed to upload: " + file.getName() + " status:" + response.getStatusCode();
        //}
      }
    }
    
    // for Debug
    accessLog += responseJson + "\n";
    
    //// == ワークフローデータへの代入 / Data Updating ==
    if( dataIdX !== "" ){
      retVal.put( dataIdX, accessLog );
    }
    

    • B’: box 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’
    • The communication logs will be stored in the Data Item selected at config X
    • It requires registering Apps at box Developers in advance
    • When specifying a root folder, set the folder ID as “0”
    • If specified a folder ID which does not exist, it results in an error
    • If there are filename conflicts, it results in an error
    • * https://{sub-domain}.app.box.com/files/0/f/11603741795/Folder-Name