mirror of
https://github.com/apache/cordova-plugin-file-transfer.git
synced 2026-06-05 00:00:35 +08:00
CB-6503: Allow payload content-types other than multipart/form-data to be used for upload
This commit is contained in:
committed by
Ian Clelland
parent
3c5988e522
commit
04f088b6c9
@@ -341,8 +341,13 @@ public class FileTransfer extends CordovaPlugin {
|
||||
|
||||
// Use a post method.
|
||||
conn.setRequestMethod(httpMethod);
|
||||
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
|
||||
|
||||
|
||||
// if we specified a Content-Type header, don't do multipart form upload
|
||||
boolean multipartFormUpload = !headers.has("Content-Type");
|
||||
if (multipartFormUpload) {
|
||||
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
|
||||
}
|
||||
|
||||
// Set the cookies on the response
|
||||
String cookie = getCookies(target);
|
||||
|
||||
@@ -389,7 +394,9 @@ public class FileTransfer extends CordovaPlugin {
|
||||
|
||||
int stringLength = beforeDataBytes.length + tailParamsBytes.length;
|
||||
if (readResult.length >= 0) {
|
||||
fixedLength = (int)readResult.length + stringLength;
|
||||
fixedLength = (int)readResult.length;
|
||||
if (multipartFormUpload)
|
||||
fixedLength += stringLength;
|
||||
progress.setLengthComputable(true);
|
||||
progress.setTotal(fixedLength);
|
||||
}
|
||||
@@ -420,10 +427,13 @@ public class FileTransfer extends CordovaPlugin {
|
||||
}
|
||||
context.connection = conn;
|
||||
}
|
||||
//We don't want to change encoding, we just want this to write for all Unicode.
|
||||
sendStream.write(beforeDataBytes);
|
||||
totalBytes += beforeDataBytes.length;
|
||||
|
||||
|
||||
if (multipartFormUpload) {
|
||||
//We don't want to change encoding, we just want this to write for all Unicode.
|
||||
sendStream.write(beforeDataBytes);
|
||||
totalBytes += beforeDataBytes.length;
|
||||
}
|
||||
|
||||
// create a buffer of maximum size
|
||||
int bytesAvailable = readResult.inputStream.available();
|
||||
int bufferSize = Math.min(bytesAvailable, MAX_BUFFER_SIZE);
|
||||
@@ -452,9 +462,11 @@ public class FileTransfer extends CordovaPlugin {
|
||||
context.sendPluginResult(progressResult);
|
||||
}
|
||||
|
||||
// send multipart form data necessary after file data...
|
||||
sendStream.write(tailParamsBytes);
|
||||
totalBytes += tailParamsBytes.length;
|
||||
if (multipartFormUpload) {
|
||||
// send multipart form data necessary after file data...
|
||||
sendStream.write(tailParamsBytes);
|
||||
totalBytes += tailParamsBytes.length;
|
||||
}
|
||||
sendStream.flush();
|
||||
} finally {
|
||||
safeClose(readResult.inputStream);
|
||||
|
||||
Reference in New Issue
Block a user