mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 20:33:07 +08:00
Prefer setFixedLengthStreamingMode over setChunkedStreamingMode in FileTransfer.
setFixedLengthStreamingMode causes the Content-Length header to be set, which some servers require. We now use setChunkedStreamingMode only on Eclair devices since there is a bug with setFixedLengthStreamingMode in that version of the OS.
This commit is contained in:
parent
81ab0a414f
commit
af0feabb6a
@ -49,6 +49,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.CookieManager;
|
import android.webkit.CookieManager;
|
||||||
|
|
||||||
@ -239,20 +240,18 @@ public class FileTransfer extends Plugin {
|
|||||||
String tailParams = LINE_END + LINE_START + BOUNDARY + LINE_START + LINE_END;
|
String tailParams = LINE_END + LINE_START + BOUNDARY + LINE_START + LINE_END;
|
||||||
byte[] fileNameBytes = fileName.getBytes("UTF-8");
|
byte[] fileNameBytes = fileName.getBytes("UTF-8");
|
||||||
|
|
||||||
// Should set this up as an option
|
|
||||||
if (chunkedMode) {
|
|
||||||
conn.setChunkedStreamingMode(maxBufferSize);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int stringLength = extraBytes.length + midParams.length() + tailParams.length() + fileNameBytes.length;
|
int stringLength = extraBytes.length + midParams.length() + tailParams.length() + fileNameBytes.length;
|
||||||
Log.d(LOG_TAG, "String Length: " + stringLength);
|
Log.d(LOG_TAG, "String Length: " + stringLength);
|
||||||
int fixedLength = (int) fileInputStream.getChannel().size() + stringLength;
|
int fixedLength = (int) fileInputStream.getChannel().size() + stringLength;
|
||||||
Log.d(LOG_TAG, "Content Length: " + fixedLength);
|
Log.d(LOG_TAG, "Content Length: " + fixedLength);
|
||||||
|
// setFixedLengthStreamingMode causes and OutOfMemoryException on pre-Froyo devices.
|
||||||
|
// http://code.google.com/p/android/issues/detail?id=3164
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO && chunkedMode) {
|
||||||
|
conn.setChunkedStreamingMode(maxBufferSize);
|
||||||
|
} else {
|
||||||
conn.setFixedLengthStreamingMode(fixedLength);
|
conn.setFixedLengthStreamingMode(fixedLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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.
|
||||||
dos.write(extraBytes);
|
dos.write(extraBytes);
|
||||||
|
Loading…
Reference in New Issue
Block a user