Hi,
There is no guarantee that this will work, but try placing
"os.flush()" in your loop. Which in theory tells the outputstream
implementation to write out the buffered data.
E.g
while ((len = is.read(buffer)) != -1){
os.write(buffer, 0, len);
os.flush();
}
I haven't looked at the underlying implementation of org.apache.http
package in Android. But perhaps it is worth investigating if you
continue to have problems.
Makas
On Mar 13, 8:17 am, AuxOne <[email protected]> wrote:
> I have some Android code that can send files to my webserver using an
> HttpsUrlConnection, but when it tries to send larger files I get an
> OutOfMemory exception when opening the OutputStream. Can anyone offer
> some assistance?
>
> It looks something like this:
>
> httpConn = (HttpsURLConnection) new URL(uri).openConnection();
> httpConn.setDoInput(true);
> httpConn.setDoOutput(true);
> httpConn.setUseCaches(false);
> httpConn.setRequestMethod("POST");
>
> This is where I try different things. The closes solution has been:
> httpConn.setChunkedStreamingMode(1024);
> In this case, I don't get the OutOfMemory immediately when opening the
> OutputStream, but I see the heap growing as I os.write() and it
> eventually runs out.
>
> httpConn.connect();
> OutputStream os = httpConn.getOutputStream();
> byte[] buffer = new byte[4096];
> int len;
> while ((len = is.read(buffer)) != -1){
> os.write(buffer, 0, len);}
>
> os.flush();
>
> Each time I open the .getOutputStream() the contents of the file I am
> trying to send is loaded into memory, per the discussion here (http://
> bugs.sun.com/bugdatabase/view_bug.do?bug_id=4212479) -- so I go out of
> memory.
>
> My server supports HTTP 1.1. I've tried the following code.
> 1. httpConn.setRequestProperty("Transfer-Encoding","chunked");
> 2. httpConn.setChunkedStreamingMode(1024);
> 3. httpConn.setRequestProperty("Content-Length", length);
> 4. httpConn.setFixedLengthStreamingMode(1024)
> 5. Combo of 1+2.
> 6. Combo of 3+4
>
> Can anyone offer any assistance?! It seems like no matter what, the
> data going to the OutputStream is being buffered. ChunkedStreamMode
> seems to just buffer it in pieces, whereas it would otherwise buffer
> it all at once. Both go out of memory.
>
> Thanks in advance.
>
> PS> I have similar code for J2ME and memory has not been a problem.
> Also, if I try to send two medium sized files in a row, the first one
> makes it, but then the heap doesn't seem to compact and the second one
> fails.
--
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