diff --git a/framework/src/org/apache/cordova/FileTransfer.java b/framework/src/org/apache/cordova/FileTransfer.java index edb1b6da..5b974638 100644 --- a/framework/src/org/apache/cordova/FileTransfer.java +++ b/framework/src/org/apache/cordova/FileTransfer.java @@ -158,6 +158,25 @@ public class FileTransfer extends CordovaPlugin { return false; } + private static void addHeadersToRequest(URLConnection connection, JSONObject headers) { + try { + for (Iterator iter = headers.keys(); iter.hasNext(); ) { + String headerKey = iter.next().toString(); + JSONArray headerValues = headers.optJSONArray(headerKey); + if (headerValues == null) { + headerValues = new JSONArray(); + headerValues.put(headers.getString(headerKey)); + } + connection.setRequestProperty(headerKey, headerValues.getString(0)); + for (int i = 1; i < headerValues.length(); ++i) { + connection.addRequestProperty(headerKey, headerValues.getString(i)); + } + } + } catch (JSONException e1) { + // No headers to be manipulated! + } + } + /** * Uploads the specified file to the server URL provided using an HTTP multipart request. * @param source Full path of the file on the file system @@ -272,22 +291,7 @@ public class FileTransfer extends CordovaPlugin { // Handle the other headers if (headers != null) { - try { - for (Iterator iter = headers.keys(); iter.hasNext(); ) { - String headerKey = iter.next().toString(); - JSONArray headerValues = headers.optJSONArray(headerKey); - if (headerValues == null) { - headerValues = new JSONArray(); - headerValues.put(headers.getString(headerKey)); - } - conn.setRequestProperty(headerKey, headerValues.getString(0)); - for (int i = 1; i < headerValues.length(); ++i) { - conn.addRequestProperty(headerKey, headerValues.getString(i)); - } - } - } catch (JSONException e1) { - // No headers to be manipulated! - } + addHeadersToRequest(conn, headers); } /* @@ -616,6 +620,7 @@ public class FileTransfer extends CordovaPlugin { final boolean trustEveryone = args.optBoolean(2); final String objectId = args.getString(3); + final JSONObject headers = args.optJSONObject(4); final URL url; try { @@ -693,6 +698,11 @@ public class FileTransfer extends CordovaPlugin { { connection.setRequestProperty("cookie", cookie); } + + // Handle the other headers + if (headers != null) { + addHeadersToRequest(connection, headers); + } connection.connect();