All,
I have been doing some tests to upload large amounts of data over a
WIFI connection. My goal is to upload 50 Meg+ files from SD card to a
webservice like Amazon S3. Of course I need to stream the file
contents in small bits as those won't fit in memory.
HttpURLConnection offers too functions for that:
* setFixedLengthStreamingMode
* setChunkedStreamingMode
I have been trying to use both but I still get out of memory
exceptions from Android even though the request object should be
sending data as it gets it. I checked with tcpdump that it actually
buffers up everything and just blows up when reaching more than 12 MB
of cache.
My code is as follow:
byte[] buf = new byte[32*1024]; // 32K buffer
int readBytes;
OutputStream os;
InputStream is; // from a file
HttpURLConnection request = (HttpURLConnection)
url.openConnection();
connection.setRequestMethod(method);
request.setDoOutput(true);
request.setFixedLengthStreamingMode(isLength);
os = request.getOutputStream();
while((readBytes = is.read(buf)) != -1) {
os.write(buf, 0, readBytes);
}
This code should not buffer content into the outputstream but should
send bytes as they are read from the input stream.
Are chunking and fixed size streaming not implemented in Android
(1.5)?
Thanks a lot for your help,
Giorgio
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---