If I upload a large file using an HttpURLConnection and
setChunkedStreamingMode the file is successfully uploaded. But, I am not
able to read the response from the server.
If I leave out streaming mode line:
conn.setChunkedStreamingMode(1000*1024);
I get an out of memory error on large file, but this works well for small
files and I get a response from the server.
Any insights on this?
Carmen
// Set up URL Connection for streaming
HttpURLConnection conn = (HttpURLConnection) connectURL.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setChunkedStreamingMode(1000*1024);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type",
"multipart/form-data;boundary="+boundary);
// Read response
// this works for small files when not in streaming mode
// for large files, connection is reset by server (time outs)
Reader reader = new InputStreamReader( conn.getInputStream() );
StringBuilder in = new StringBuilder( 32000 );
int x;
while ( (x=reader.read()) != -1 ){
in.append( (char)x );
}
--
Carmen
http://www.twitter.com/CarmenDelessio
http://www.talkingandroid.com
http://www.facebook.com/BFFPhoto
http://www.twitter.com/DroidDrop
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en