I have scenario where i need to transfer one or more file depending on situation over the network. The size of the files will be between 700KB and 900KB. After upload completes the server will respond with one number, irrespective of the number of files uploaded.
I have been trying to upload it with ksoap2 library after converting it to Base64, but it failed. It would fail when size of my soap header xml size goes around some where 1048000 or so chars.
Then i decided to change my way of upload and am looking to use either HttpURLConnection or http client.
I cannot decide on which one will be efficient for my scenario.
Thanks
Here is the code
code:
InputStream is = getResources()
.openRawResource(R.raw.file_name);
int size = 0;
// Read the entire resource into a local byte buffer.
byte[] buffer = new byte[1024];
try {
while ((size = is.read(buffer, 0, 1024)) >= 0) {
baos.write(buffer, 0, size);
}
is.close();
buffer = baos.toByteArray();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
base64string = new String(Base64.encode(buffer, Base64.DEFAULT));
error
org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:1 in java.io.InputStreamReader@4101ce48)
at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:2035)
at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:126)
at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
I dont know what kind of server you would like to use.
Your issue of that the files stops while upload might be in your server settings. in your php config for example you can define maximum uploaded file sizes etc.
here a php example:
Read more: http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html#ixzz27YPjwX8B
EDIT: You could also try to make your soap transfer more efficient by implementing MTOM:
Check out MTOM, a W3C standard designed to transfer binary files through SOAP.
From Wikipedia:
Related resources:
SOAP Message Transmission Optimization Mechanism http://www.w3.org/TR/soap12-mtom/
Message Transmission Optimization Mechanism (Wikipedia) http://en.wikipedia.org/wiki/MTOM