IS can handle most HTTP POSTs just fine, but binary file uploads are tricky. Just thought I’d put together a thread on the steps I took to get it running.
Also see an older thread:
“HTTP File upload”
[url]wmusers.com
This is a thread on downloading binary files from IS:
“Downloading a binary file through an IS service”
[url]wmusers.com
1. Ensure you have webMethods’ multipart content handler installed
webMethods has developed a content handler for multipart/form-data HTTP POSTs. I understand it is automatically installed by the IS 6.x package WmBrokerAdmin that uses it for ADL file uploads. If the handler is not installed, webMethods can supply a zip package named ContentHandler.zip which contains JAR files from WmBrokerAdmin. This is a 6.x package, but it works fine on IS 4.6.
2. Create the HTML form for your file upload.
Note, the FORM element ‘enctype’ attribute must be set to “multipart/form-data” and INPUT element must be of type ‘file’. For eg:
[html]
3. Access the uploaded data
I chose to name the HTML file input element “uploadFile”, but you can name it anything you like. When the file is uploaded, the multipart content handler automatically inserts a record with the same name (‘uploadFile’ in my case) into the pipeline. The record structure looks like this:
uploadFile (Record)
uploadFile/filename (string)
uploadFile/data (object)
uploadFile/type (string)
The handler also inserts in an array of ‘uploadFileList’ records – this is how WM caters to multiple elements in an HTML form having the same name.
You now need to define an appropriately named record with this structure as the input specification of the upload receive service. You can now access data in <record_name>/data, which is a java byte array. For instance, this is Java code for a service that will take the data and write it to disk:
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String fileName = IDataUtil.getString( pipelineCursor, "fileName" );
byte[] contentBytes = (byte []) IDataUtil.get( pipelineCursor, "data" );
pipelineCursor.destroy();
// pipeline
try {
FileOutputStream fos = new FileOutputStream(fileName);
fos.write(contentBytes);
}
catch (Exception e) {throw new ServiceException(e);}