Send Multipart Data
The following program provides a more detailed example that includes sending multipart data to a Media Server for processing. This example uses the aciObjectParamSetFile function to upload the source data and task configuration files.
To run this example program, you set four arguments at the command line.
program.exe host port filepath taskconfig
where,
programis the name that you use for the executable file.hostis the host name or IP address of the Media Server to send the action to.portis the port of the Media Server to send the action to.filepathis the path to the source file to upload to the Media Server. This path is sent to theSourceDataparameter in the Media ServerProcessaction.taskconfigis the path to the task configuration file to upload to the Media Server. This value is sent to theConfigparameter in the Media ServerProcessaction.
For more information about the Media Server actions, refer to the Media Server Administration Guide and the Media Server Reference.
The example program runs the following steps:
- Check the number of command-line parameters.
- Set up a connection to Media Server, using the
hostandportvalues provided. - Set up a command to Media Server, using the
filepathandtaskconfigvalues provided. - Send the request and print the response to
stdout.
#include "client.h"
#include <stdio.h>
#include <stdlib.h>
// Checks the value of an ACI error. If not successful, logs an error and jumps to
// next 'clean' label
#define CHECK_ACI_ERROR(_nAciError) if ((_nAciError) != ACICONTENT_SUCCESS) { \
fprintf(
stderr, "ACI Client failed at %s:%d: %s\n", __FILE__, __LINE__,
acioGetErrorDescription(_nAciError)
); \
nRet = _nAciError; \
goto clean;\
}
int main(int argc, char** argv)
{
int nRet = EXIT_SUCCESS;
const char* szHostname = NULL;
int nPort = 0;
const char* szFilePath = NULL;
t_aciObject* pConnection = NULL;
t_aciObject* pCommand = NULL;
char* szResult = NULL;
int nBufferLength = 0;
char* szContentType = NULL;
const char* szTaskConfig = "task.cfg";
// Always need to call aciInit at start of any program using ACI client lib
aciInit();
// 1. Checks number of command line parameters
if (argc != 5)
{
fprintf(stderr, "Usage: %s HOST PORT FILEPATH TASKCONFIG\n", argv[0]);
return -17;
}
szHostname = argv[1];
nPort = atoi(argv[2]);
szFilePath = argv[3];
szTaskConfig = argv[4];
// Setup connection
CHECK_ACI_ERROR(aciObjectCreate(&pConnection, ACI_CONNECTION));
CHECK_ACI_ERROR(aciObjectParamSetString(pConnection, ACI_HOSTNAME, szHostname));
CHECK_ACI_ERROR(aciObjectParamSetInt (pConnection, ACI_PORTNUMBER, nPort));
CHECK_ACI_ERROR(aciObjectParamSetInt (pConnection, ACI_CONN_RETRIES, 10));
CHECK_ACI_ERROR(aciObjectParamSetInt (pConnection, ACI_CONN_TIMEOUT, 120000));
CHECK_ACI_ERROR(
aciObjectParamSetInt (pConnection, ACI_CONN_TIMEOUT_READ, 120000)
);
// Setup command
CHECK_ACI_ERROR(aciObjectCreate(&pCommand, ACI_COMMAND));
CHECK_ACI_ERROR(aciObjectParamSetBool (pCommand, ACI_COM_USE_POST, TRUE));
CHECK_ACI_ERROR(
aciObjectParamSetBool (pCommand, ACI_COM_USE_MULTIPART, TRUE)
);
CHECK_ACI_ERROR(
aciObjectParamSetString (pCommand, ACI_COM_COMMAND, "process")
);
CHECK_ACI_ERROR(aciObjectParamSetBool (pCommand, "synchronous", TRUE));
CHECK_ACI_ERROR(aciObjectParamSetFile (pCommand, "SourceData", szFilePath));
CHECK_ACI_ERROR(aciObjectParamSetFile (pCommand, "Config", szTaskConfig));
// Send command, get result, print result
fprintf(stdout, "Sending process command for %s to %s:%d\n",
szFilePath, szHostname, nPort);
CHECK_ACI_ERROR(
aciObjectExecuteToString(pConnection, pCommand, &szResult,
&nBufferLength, &szContentType)
);
fprintf(stdout, "%s\n", szResult);
clean:
free(szResult); szResult = NULL;
free(szContentType); szContentType = NULL;
aciObjectDestroy(&pCommand);
aciObjectDestroy(&pConnection);
// Always need to call aciShutDown at end of any program using ACI client lib
aciShutDown();
return nRet;
}