mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
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:
parent
e42913ae8a
commit
999c548e6e
@ -251,6 +251,7 @@ public class FileTransfer extends Plugin {
|
|||||||
} else {
|
} else {
|
||||||
conn.setFixedLengthStreamingMode(fixedLength);
|
conn.setFixedLengthStreamingMode(fixedLength);
|
||||||
}
|
}
|
||||||
|
conn.setRequestProperty("Transfer-Encoding", "chunked");
|
||||||
|
|
||||||
dos = new DataOutputStream( conn.getOutputStream() );
|
dos = new DataOutputStream( conn.getOutputStream() );
|
||||||
//We don't want to change encoding, we just want this to write for all Unicode.
|
//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);
|
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
||||||
totalBytes = 0;
|
totalBytes = 0;
|
||||||
|
|
||||||
|
long prevBytesRead = 0;
|
||||||
while (bytesRead > 0) {
|
while (bytesRead > 0) {
|
||||||
totalBytes += bytesRead;
|
totalBytes += bytesRead;
|
||||||
result.setBytesSent(totalBytes);
|
result.setBytesSent(totalBytes);
|
||||||
dos.write(buffer, 0, bufferSize);
|
dos.write(buffer, 0, bufferSize);
|
||||||
|
if (totalBytes > prevBytesRead + 102400) {
|
||||||
|
prevBytesRead = totalBytes;
|
||||||
|
Log.d(LOG_TAG, "Uploaded " + totalBytes + " of " + fixedLength + " bytes");
|
||||||
|
}
|
||||||
bytesAvailable = fileInputStream.available();
|
bytesAvailable = fileInputStream.available();
|
||||||
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
||||||
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
||||||
|
Loading…
Reference in New Issue
Block a user