/*************************************************************************************** * IBM Confidential * * OCO Source Materials * * IBM Cognos Products: Moser * * (C) Copyright IBM Corp. 2020 * * The source code for this program is not published or otherwise * divested of its trade secrets, irrespective of what has been * deposited with the U.S. Copyright Office. * ***************************************************************************************/ import java.io.IOException; import com.ibm.bi.platform.modeling.sdk.examples.FileImportHelper; import com.ibm.bi.platform.modeling.sdk.examples.internal.ModelingHelper; import com.ibm.bi.platform.modeling.sdk.examples.internal.UnexpectedHTTPResponseException; import com.ibm.json.java.JSONObject; /** * Upload file from folder to a public directory * */ public class UploadFileExample { /** * @param args * args[0] ca server url origin, e.g. http://localhost:9300/ * args[1] login credentials relative file path * args[2] directory containing file relative to current , e.g. "resources/" * args[3] file to upload name, e.g. "pizza.xlsx" * args[4] destination folder store id */ public static void main(String[] args) { if (args.length < 5) { System.err.print("Correct arguments: origin fileWithCredentials sourceDir filename destinationStoreId"); return; } String origin = args[0]; try { FileImportHelper helper = new FileImportHelper(origin); String credentials = ModelingHelper.stringFromFile(args[1]); helper.authenticate(credentials); String dir = args[2], filename = args[3], destination = args[4]; // Post the file. String response = helper.uploadFile(dir, filename, destination); JSONObject json = JSONObject.parse(response); String uploadedId = (String) json.get("id"); System.out.println("File is uploaded : " + uploadedId); } catch (UnexpectedHTTPResponseException e) { try { System.out.println("Response : " + ModelingHelper.httpEntityToString(e.getResponse().getEntity())); } catch (IOException io) { } e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }