Fix FileTransfer running out of memory over HTTPS (CB-312).

Setting the Transfer-Encoding header fixes running out of memory when
using HTTPS.
This CL also adds a bit of logging so that upload progress is logged.
This commit is contained in:
Andrew Grieve 2012-08-16 10:25:54 -04:00
parent e42913ae8a
commit 999c548e6e

View File

@ -251,6 +251,7 @@ public class FileTransfer extends Plugin {
} else {
conn.setFixedLengthStreamingMode(fixedLength);
}
conn.setRequestProperty("Transfer-Encoding", "chunked");
dos = new DataOutputStream( conn.getOutputStream() );
//We don't want to change encoding, we just want this to write for all Unicode.
@ -267,10 +268,15 @@ public class FileTransfer extends Plugin {
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
totalBytes = 0;
long prevBytesRead = 0;
while (bytesRead > 0) {
totalBytes += bytesRead;
result.setBytesSent(totalBytes);
dos.write(buffer, 0, bufferSize);
if (totalBytes > prevBytesRead + 102400) {
prevBytesRead = totalBytes;
Log.d(LOG_TAG, "Uploaded " + totalBytes + " of " + fixedLength + " bytes");
}
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);