E-com DevBlog Spider-ball-vacuum

6Oct/090

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.

Print This Post Print This Post
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.