Uploading Files in an Apache Axis Webservice

October 6th, 2009 | Tags:
uploading-files-in-an-apache-axis-webservice

Being somewhat new to the Apache Axis webservice world, I’ve been looking for a solution on how to upload a file via the webservice. I found some MIME and DIME formats and there was even some cool looking technologies about MTOM (see here).

In the end the simple answer I found, on the same page linked to above, was to encode the file as a Base64 string and put it in the request like a normal string. Then on the service side it is simply decoded.

For example:
On the client side:

String base64Encoding = Base64.encode(byteArrayFromFile); 
.
.
.
//In the XML request
.append("<ns1:encodedFile>")
    .append(base64Encoding)
.append("</ns1:encodedFile>")

And then in the service:

String base64String = request.getEncodedFile();
byte[] byteArray = Base64.decode(base64String);

And then with the byteArray you can save it or do whatever you need.

No comments yet.
TOP