HTTP uploading a binary file to IS

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]

[/html] When you test this in your browser, a 'Browse' button automatically appears next to the file input element.

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);}

A quick update to my post above:

If you run into problems submitting the HTML form containing the file upload, try removing any Javascript submits for the form. i.e don’t submit the form using the Javascript call “document..submit()” - just use a plain HTML submit. My suspicion is that somehow Javascript resets the form’s enctype back to the default: “application/x-www-form-urlencoded”.

Sonam,

Can you provide me the ContentHandler.zip?

Thanks in advance

Kevin

Hi Kevin - sorry, just saw your post now.

I can’t provide the ContentHandler.zip as it is copyrighted by webMethods.

However, you can get it from WM support.

Regards,
sonam

Hi Sonam

I have the same issue about uploading the file using DSP which I couldn’t get the data in the uploaded file. I tried contacting the webMethods support guy to provide the ContentHandler.zip, but he said wm doesn’t ahave any package by that name.

Could you please provide a link that I can download ContentHandler.zip ?

Thanks
Satish

Satish - Just saw your post. I can’t provide a link to ContentHandler.zip for the copyright reasons mentioned above.

A HTTP POST for file upload (as executed for example, by the sample HTML form above), are of Content-Type ‘multipart/form-data’. webMethods’ default content handler does not handle these type of POSTs, but ContentHandler.zip does.

The ContentHandler.zip file used to be automatically installed by the IS 6.x WmBrokerAdmin package and was used there to handle file uploads from an DSP admin webpage. If this package is not installed or available for your platform version, try asking webMethods to supply it or it’s equivalent for your platform. You can also try writing a content handler. As a last resort, try installing 6.1/6.5 WmBrokerAdmin via webMethods Installer and poaching the package from there. However, check with support, and test before you try this in production.

Thanks for the reply.

I did this using mime services.

Is there any that we can seperate the actual file content from the other field data that is sent in the same form?

Hi Satish,

Can you please tell me in detail how you have done this using mime services.

regards,
Satya

Is there a way to verify that you have the right contenthandler installed & setup in your IS??

Sonam - I followed all the steps that you mentioned, but I’m not able to get my I/p document populated with all the values…could you please help me give some pointers to where might be the issue? How could I verify the success of step 1

Hi All,

After submit, i can get the data in my flowservice. But after clicking on submit button how will i take to next page which diplays successfully uploaded or return with error message from flowservice while uploading.

Can someone please provide a solution to this.

Thanks in advance.

Regards,
Naveen

You can make use of the Output template of the flowservice that you are invoking.

Hi Suren,

Thanks for your reply.

I tried using the output template, but after i upload the data and click on submit button a pop up appears with options to “open”, “save”, “cancel” and “more info”. If i open this i find my html code in this file. But it doesnt take me to the intended html page after uploading.

Please help me on this. Your comments are valuable to me.

Regards,
Naveen

Naveen,

If you could post the output template that you have in your service here, it would be easy for to know what is happening.

BTW, this time did you get the file data in the pipeline…?