mirror of
https://github.com/apache/cordova-plugin-file-transfer.git
synced 2026-04-28 00:02:49 +08:00
CB-10974 Cordova file transfer Content-Length header problem
Don't force chunkedMode=true for HTTPS if it was specified as false in the UploadOptions (added a warning about possible OOM for chunkedMode=false+HTTPS case)
This commit is contained in:
@@ -430,7 +430,7 @@ public class FileTransfer extends CordovaPlugin {
|
|||||||
// setFixedLengthStreamingMode causes and OutOfMemoryException on pre-Froyo devices.
|
// setFixedLengthStreamingMode causes and OutOfMemoryException on pre-Froyo devices.
|
||||||
// http://code.google.com/p/android/issues/detail?id=3164
|
// http://code.google.com/p/android/issues/detail?id=3164
|
||||||
// It also causes OOM if HTTPS is used, even on newer devices.
|
// It also causes OOM if HTTPS is used, even on newer devices.
|
||||||
boolean useChunkedMode = chunkedMode || (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO || useHttps);
|
boolean useChunkedMode = chunkedMode || (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO);
|
||||||
useChunkedMode = useChunkedMode || (fixedLength == -1);
|
useChunkedMode = useChunkedMode || (fixedLength == -1);
|
||||||
|
|
||||||
if (useChunkedMode) {
|
if (useChunkedMode) {
|
||||||
@@ -440,6 +440,10 @@ public class FileTransfer extends CordovaPlugin {
|
|||||||
conn.setRequestProperty("Transfer-Encoding", "chunked");
|
conn.setRequestProperty("Transfer-Encoding", "chunked");
|
||||||
} else {
|
} else {
|
||||||
conn.setFixedLengthStreamingMode(fixedLength);
|
conn.setFixedLengthStreamingMode(fixedLength);
|
||||||
|
|
||||||
|
if (useHttps) {
|
||||||
|
LOG.w(LOG_TAG, "setFixedLengthStreamingMode could cause OutOfMemoryException - switch to chunkedMode=true to avoid it if this is an issue.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.connect();
|
conn.connect();
|
||||||
@@ -564,7 +568,6 @@ public class FileTransfer extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
// Revert back to the proper verifier and socket factories
|
|
||||||
// Revert back to the proper verifier and socket factories
|
// Revert back to the proper verifier and socket factories
|
||||||
if (trustEveryone && useHttps) {
|
if (trustEveryone && useHttps) {
|
||||||
HttpsURLConnection https = (HttpsURLConnection) conn;
|
HttpsURLConnection https = (HttpsURLConnection) conn;
|
||||||
|
|||||||
Reference in New Issue
Block a user