Wordpress.Com: Media New
Uploads new pieces of media. If you want to dynamically change the WORDPRESS DOMAIN of the upload destination using the EL expression, set Scope to “global”.
https://support.questetra.com/addons/wordpress-com-media-new/
2018-12-11 (C) Questetra, Inc. (MIT License)
Configs
  • A: Select FILES DATA for Upload *
  • B: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *
  • C: Set WORDPRESS DOMAIN to Upload (e.g. “example.com” or ID) * #{EL}
Script
// (c) 2018, Questetra, Inc. (the MIT License)

//// == OAuth2 Setting example ==
// Authorization Endpoint URL:
//  "https://public-api.wordpress.com/oauth2/authorize"
// Token Endpoint URL:
//  "https://public-api.wordpress.com/oauth2/token"
// Scope: "global" (or "auth")
// Client ID: ( from https://developer.wordpress.com/apps/ )
// Consumer Secret: ( from https://developer.wordpress.com/apps/ )
// -- "Redirect URLs": "https://s.questetra.net/oauth2callback"
// -more-
// https://developer.wordpress.com/docs/oauth2/
// https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/media/new/


//////// START "main()" ////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA  = configs.get( "conf_DataIdA" ) + "";
const oauth2   = configs.get( "conf_OAuth2" ) + "";
const wpDomain = configs.get( "conf_WpDomain" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'
if(wpDomain === ""){
  throw new Error( '\n WordPress Domain not Defined \n' );
}

//// == Data Retrieving / ワークフローデータの参照 ==
const myFiles  = engine.findDataByNumber( dataIdA ); 
// java.util.ArrayList
if (myFiles == null) {
  throw new Error( '\n Files not Attached \n' );
}
const numFiles = myFiles.size() - 0; // javascript 'number'
// myFiles[i]: com.questetra.bpms.core.event.scripttask.QfileView


//// == Calculating / 演算 ==
/// obtain OAuth2 Access Token
const token   = httpClient.getOAuth2Token( oauth2 );

for(let i = 0; i < numFiles; i++){
  /// prepare API Request
  let apiRequest = httpClient.begin(); // HttpRequestWrapper
  // - com.questetra.bpms.core.event.scripttask.HttpClientWrapper
  apiRequest     = apiRequest.bearer( token );
  apiRequest     = apiRequest.multipart( "media[]", myFiles[i] );

  /// access API (with post(), get(), put(), etc.)
  const apiUri = "https://public-api.wordpress.com/rest/v1.1/sites/"
                 + wpDomain + "/media/new";
  const response = apiRequest.post( apiUri );
  // - HttpResponseWrapper
  const httpStatus  = response.getStatusCode() + "";
  engine.log( "STATUS: " + httpStatus );
  const responseStr = response.getResponseAsString() + "";
  engine.log( "RESPONSE: \n" + responseStr );
}


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

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

Download

WordPressCom-Media-New.xml

Capture

3 thoughts on “WordPress.Com: Media New”

  1. Pingback: Wordpress.Com: Stats Views – Questetra Support

  2. Pingback: My Experience Story on SaaS WordPress - Questetra

  3. Pingback: WordPress.Com: Posts New – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.