/** Operation Execution Methods Sync * */ public <T> T execute(String operationId, OperationBody body) { Object input = body.getInput(); if (input instanceof Blob) { // If input is blob or blobs -> use multipart List<MultipartBody.Part> filePart = new ArrayList<>(); RequestBody fbody = RequestBody.create( MediaType.parse(((Blob) input).getMimeType()), ((Blob) input).getFile()); filePart.add( MultipartBody.Part.createFormData(INPUT_PART, ((Blob) input).getFileName(), fbody)); return (T) getResponse(operationId, body, filePart); } else if (input instanceof Blobs) { // If input is blob or blobs -> use multipart List<MultipartBody.Part> fileParts = new ArrayList<>(); for (int i = 0; i < ((Blobs) input).size(); i++) { Blob fileBlob = ((Blobs) input).getBlobs().get(i); RequestBody fbody = RequestBody.create(MediaType.parse(fileBlob.getMimeType()), fileBlob.getFile()); fileParts.add( MultipartBody.Part.createFormData( INPUT_PARTS + String.valueOf(i), fileBlob.getFileName(), fbody)); } return (T) getResponse(operationId, body, fileParts); } else { return (T) getResponse(operationId, body); } }
/** Operation Execution Methods Async * */ public void execute(String operationId, OperationBody body, Callback<Object> callback) { Object input = body.getInput(); if (input instanceof Blob) { // If input is blob or blobs -> use multipart Map<String, RequestBody> fbodys = new HashMap<>(); RequestBody fbody = RequestBody.create( MediaType.parse(((Blob) input).getMimeType()), ((Blob) input).getFile()); fbodys.put(INPUT_PART, fbody); super.execute(callback, operationId, body, fbodys); } else if (input instanceof Blobs) { // If input is blob or blobs -> use multipart Map<String, RequestBody> fbodys = new HashMap<>(); for (int i = 0; i < ((Blobs) input).size(); i++) { Blob fileBlob = ((Blobs) input).getBlobs().get(i); RequestBody fbody = RequestBody.create(MediaType.parse(fileBlob.getMimeType()), fileBlob.getFile()); fbodys.put(INPUT_PARTS + String.valueOf(i), fbody); } super.execute(callback, operationId, body, fbodys); } else { super.execute(callback, operationId, body); } }