From 051ada102e617478a1a47c1eee8d224665f45b88 Mon Sep 17 00:00:00 2001 From: aroberson Date: Mon, 15 Jun 2015 15:54:27 -0500 Subject: [PATCH 1/3] Added option to allow for passing cookies automatically in the browser --- www/browser/FileTransfer.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/www/browser/FileTransfer.js b/www/browser/FileTransfer.js index e142222..98816ee 100644 --- a/www/browser/FileTransfer.js +++ b/www/browser/FileTransfer.js @@ -109,6 +109,7 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro var fileName = options.fileName || "image.jpg"; var mimeType = options.mimeType || "image/jpeg"; var params = options.params || {}; + var withCredentials = options.withCredentials || false; // var chunkedMode = !!options.chunkedMode; // Not supported var headers = options.headers || {}; var httpMethod = options.httpMethod && options.httpMethod.toUpperCase() === "PUT" ? "PUT" : "POST"; @@ -121,6 +122,9 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro var that = this; var xhr = transfers[this._id] = new XMLHttpRequest(); + if (withCredentials) { + xhr.withCredentials = true; + } var fail = errorCallback && function(code, status, response) { transfers[this._id] && delete transfers[this._id]; @@ -222,6 +226,7 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro options = options || {}; var headers = options.headers || {}; + var withCredentials = options.withCredentials || false; var basicAuthHeader = getBasicAuthHeader(source); if (basicAuthHeader) { @@ -231,7 +236,9 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro var that = this; var xhr = transfers[this._id] = new XMLHttpRequest(); - + if (withCredentials) { + xhr.withCredentials = true; + } var fail = errorCallback && function(code, status, response) { transfers[that._id] && delete transfers[that._id]; // In XHR GET reqests we're setting response type to Blob From f52d324b4fe516256c16c23eaf18ea3a3bf1ca19 Mon Sep 17 00:00:00 2001 From: aroberson Date: Mon, 15 Jun 2015 16:03:56 -0500 Subject: [PATCH 2/3] Updated documentation for browser --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 4ee0774..f821cd1 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,9 @@ A `FileUploadResult` object is passed to the success callback of the - Does not support `responseCode` or `bytesSent`. +### Browser Quirks + +- __withCredentials__: _boolean_ that tells the browser to set the withCredentials flag on the XMLHttpRequest ## download @@ -230,6 +233,10 @@ __Parameters__: - Download requests is being cached by native implementation. To avoid caching, pass `if-Modified-Since` header to download method. +### Browser Quirks + +- __withCredentials__: _boolean_ that tells the browser to set the withCredentials flag on the XMLHttpRequest + ## abort Aborts an in-progress transfer. The onerror callback is passed a FileTransferError object which has an error code of FileTransferError.ABORT_ERR. From f17b7fcdd109eaf5e51db68cc7b316380e93ceef Mon Sep 17 00:00:00 2001 From: aroberson Date: Mon, 15 Jun 2015 20:38:21 -0500 Subject: [PATCH 3/3] Updated code per code review. --- www/browser/FileTransfer.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/www/browser/FileTransfer.js b/www/browser/FileTransfer.js index 98816ee..2146ed1 100644 --- a/www/browser/FileTransfer.js +++ b/www/browser/FileTransfer.js @@ -122,9 +122,7 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro var that = this; var xhr = transfers[this._id] = new XMLHttpRequest(); - if (withCredentials) { - xhr.withCredentials = true; - } + xhr.withCredentials = withCredentials; var fail = errorCallback && function(code, status, response) { transfers[this._id] && delete transfers[this._id]; @@ -236,9 +234,7 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro var that = this; var xhr = transfers[this._id] = new XMLHttpRequest(); - if (withCredentials) { - xhr.withCredentials = true; - } + xhr.withCredentials = withCredentials; var fail = errorCallback && function(code, status, response) { transfers[that._id] && delete transfers[that._id]; // In XHR GET reqests we're setting response type to Blob