1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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;
- public class UploadFileExample {
-
- 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];
-
- 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();
- }
- }
- }
|