> I suspect your problem is not in reading the InputStream, but rather in
> how FilePart does what it does. Since that isn't part of Android, it was
> probably developed without tight memory constraints in mind. If you hand
> it 1 KB chunks each time, it is probably going to allocate a 1 KB byte
> array, then a 2 KB byte array, then a 3 KB byte array, then a 4 KB byte
> array, and so on. You are hopelessly fragmenting your heap. Not to
> mention that FilePart might well wind up Base64 encoding the result,
> requiring another massive memory allocation.

OK, I see. Although, I do get the OutofMemoryError on the
byteBuffer.write(buffer, 0, len), well before I do anything with the
FilePart.

Do you think that even if I managed to fix the byteBuffer issue, I'd
still hit problems when I got to FilePart?

> I would recommend rewriting your Web server. Use HTTP PUT instead of
> HTTP POST with multipart. Better yet, use HTTP PUT and support chunking
> on the Web server -- you do a PUT for every 1MB or so and the server
> stitches them together.

It is my Web server, so I can rewrite it to accept a PUT request. Are
you suggesting that I do something like this, for each 1MB of the
data?

   HttpPut httpPut = new HttpPut(url);
   httpPut.setEntity(new StringEntity(data));

I'll try it and let people know here (and on Stack Overflow!) how it
goes.

Thank you for the advice, as ever :)

-- 
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

Reply via email to