You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2015/02/12 02:48:57 UTC
[01/13] cordova-plugin-file-transfer git commit: android: Fix error
reporting for unknown uri type on sourceUri instead of targetUri
Repository: cordova-plugin-file-transfer
Updated Branches:
refs/heads/master 926917247 -> 49c21f951
android: Fix error reporting for unknown uri type on sourceUri instead of targetUri
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/0aae9449
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/0aae9449
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/0aae9449
Branch: refs/heads/master
Commit: 0aae94495f68ef110cfcc4b3e0900d4b3a30ce46
Parents: c12f1eb
Author: Kelly Campbell <ke...@gmail.com>
Authored: Sat Jan 31 17:05:41 2015 -0500
Committer: Kelly Campbell <ke...@gmail.com>
Committed: Sat Jan 31 22:34:33 2015 -0500
----------------------------------------------------------------------
src/android/FileTransfer.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/0aae9449/src/android/FileTransfer.java
----------------------------------------------------------------------
diff --git a/src/android/FileTransfer.java b/src/android/FileTransfer.java
index 3ec49f9..011a9fd 100644
--- a/src/android/FileTransfer.java
+++ b/src/android/FileTransfer.java
@@ -713,7 +713,7 @@ public class FileTransfer extends CordovaPlugin {
final boolean isLocalTransfer = !useHttps && uriType != CordovaResourceApi.URI_TYPE_HTTP;
if (uriType == CordovaResourceApi.URI_TYPE_UNKNOWN) {
JSONObject error = createFileTransferError(INVALID_URL_ERR, source, target, null, 0, null);
- Log.e(LOG_TAG, "Unsupported URI: " + targetUri);
+ Log.e(LOG_TAG, "Unsupported URI: " + sourceUri);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
return;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[06/13] cordova-plugin-file-transfer git commit: CB-7957 Adds support
for `browser` platform
Posted by pu...@apache.org.
CB-7957 Adds support for `browser` platform
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/bb0ed704
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/bb0ed704
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/bb0ed704
Branch: refs/heads/master
Commit: bb0ed704a8e1b09d61ba603d43bb2319919ac07f
Parents: 837771c
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Fri Jan 30 10:17:33 2015 +0300
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:46:01 2015 -0800
----------------------------------------------------------------------
doc/index.md | 1 +
plugin.xml | 7 +
tests/tests.js | 44 ++++--
www/browser/FileTransfer.js | 325 +++++++++++++++++++++++++++++++++++++++
4 files changed, 365 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/bb0ed704/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 81710b1..4c2236b 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -39,6 +39,7 @@ Although in the global scope, they are not available until after the `deviceread
- Amazon Fire OS
- Android
- BlackBerry 10
+- Browser
- Firefox OS**
- iOS
- Windows Phone 7 and 8*
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/bb0ed704/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index d9ee6eb..cb85a32 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -161,4 +161,11 @@
<runs/>
</js-module>
</platform>
+
+ <!-- browser -->
+ <platform name="browser">
+ <js-module src="www/browser/FileTransfer.js" name="BrowserFileTransfer">
+ <clobbers target="window.FileTransfer" />
+ </js-module>
+ </platform>
</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/bb0ed704/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index f64a4b0..ffbed50 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -19,15 +19,17 @@
*
*/
-/* global exports, cordova */
-/* global describe, it, expect, beforeEach, afterEach, jasmine, pending, spyOn */
+/*global exports, cordova, FileTransfer, FileTransferError,
+ FileUploadOptions, LocalFileSystem, requestFileSystem, TEMPORARY */
-/* global FileTransfer, FileTransferError, FileUploadOptions, LocalFileSystem */
+/*global describe, it, expect, beforeEach, afterEach, spyOn,
+ jasmine, pending*/
exports.defineAutoTests = function () {
// constants
var GRACE_TIME_DELTA = 300; // in milliseconds
+ var DEFAULT_FILESYSTEM_SIZE = 1024*50; //filesystem size in bytes
var UNKNOWN_HOST = "http://foobar.apache.org";
var HEADERS_ECHO = "http://whatheaders.com"; // NOTE: this site is very useful!
@@ -42,6 +44,9 @@ exports.defineAutoTests = function () {
return (cordova.platformId === "windows") || (navigator.appVersion.indexOf("MSAppHost/1.0") !== -1);
};
+ var isBrowser = cordova.platformId === 'browser';
+ var isIE = isBrowser && navigator.userAgent.indexOf('Trident') >= 0;
+
describe('FileTransferError', function () {
it('should exist', function () {
@@ -140,7 +145,14 @@ exports.defineAutoTests = function () {
throw new Error('aborted creating test file \'' + name + '\': ' + evt);
};
- writer.write(content + "\n");
+ if (cordova.platformId === 'browser') {
+ // var builder = new BlobBuilder();
+ // builder.append(content + '\n');
+ var blob = new Blob([content + '\n'], { type: 'text/plain' });
+ writer.write(blob);
+ } else {
+ writer.write(content + "\n");
+ }
}, unexpectedCallbacks.fileOperationFail);
},
@@ -157,7 +169,12 @@ exports.defineAutoTests = function () {
expect(event.total).not.toBeLessThan(event.loaded);
expect(event.lengthComputable).toBe(true, 'lengthComputable');
} else {
- expect(event.total).toBe(0);
+ // In IE, when lengthComputable === false, event.total somehow is equal to 2^64
+ if (isIE) {
+ expect(event.total).toBe(Math.pow(2, 64));
+ } else {
+ expect(event.total).toBe(0);
+ }
}
};
@@ -176,7 +193,7 @@ exports.defineAutoTests = function () {
// signifies a completed async call, each async call needs its own done(), and
// therefore its own beforeEach
beforeEach(function (done) {
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
+ window.requestFileSystem(LocalFileSystem.PERSISTENT, DEFAULT_FILESYSTEM_SIZE,
function (fileSystem) {
persistentRoot = fileSystem.root;
done();
@@ -188,7 +205,7 @@ exports.defineAutoTests = function () {
});
beforeEach(function (done) {
- window.requestFileSystem(LocalFileSystem.TEMPORARY, 0,
+ window.requestFileSystem(LocalFileSystem.TEMPORARY, DEFAULT_FILESYSTEM_SIZE,
function (fileSystem) {
tempRoot = fileSystem.root;
done();
@@ -210,7 +227,7 @@ exports.defineAutoTests = function () {
}
// but run the implementations of the expected callbacks
- for (callback in expectedCallbacks) {
+ for (callback in expectedCallbacks) { //jshint ignore: line
if (expectedCallbacks.hasOwnProperty(callback)) {
spyOn(expectedCallbacks, callback).and.callThrough();
}
@@ -361,10 +378,8 @@ exports.defineAutoTests = function () {
var fileURL = window.location.protocol + '//' + window.location.pathname.replace(/ /g, '%20');
- if (!/^file/.exec(fileURL) && cordova.platformId !== 'blackberry10') {
- if (cordova.platformId !== 'windowsphone')
- expect(fileURL).toMatch(/^file:/);
- else
+ if (!/^file:/.exec(fileURL) && cordova.platformId !== 'blackberry10') {
+ if (cordova.platformId === 'windowsphone')
expect(fileURL).toMatch(/^x-wmapp0:/);
done();
return;
@@ -553,6 +568,11 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.30 downloaded file entries should have a toNativeURL method", function (done) {
+ if (cordova.platformId === 'browser') {
+ pending();
+ return;
+ }
+
var fileURL = SERVER + "/robots.txt";
var downloadWin = function (entry) {
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/bb0ed704/www/browser/FileTransfer.js
----------------------------------------------------------------------
diff --git a/www/browser/FileTransfer.js b/www/browser/FileTransfer.js
new file mode 100644
index 0000000..e142222
--- /dev/null
+++ b/www/browser/FileTransfer.js
@@ -0,0 +1,325 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+/*global module, require*/
+
+var argscheck = require('cordova/argscheck'),
+ FileTransferError = require('./FileTransferError');
+
+function getParentPath(filePath) {
+ var pos = filePath.lastIndexOf('/');
+ return filePath.substring(0, pos + 1);
+}
+
+function getFileName(filePath) {
+ var pos = filePath.lastIndexOf('/');
+ return filePath.substring(pos + 1);
+}
+
+function getUrlCredentials(urlString) {
+ var credentialsPattern = /^https?\:\/\/(?:(?:(([^:@\/]*)(?::([^@\/]*))?)?@)?([^:\/?#]*)(?::(\d*))?).*$/,
+ credentials = credentialsPattern.exec(urlString);
+
+ return credentials && credentials[1];
+}
+
+function getBasicAuthHeader(urlString) {
+ var header = null;
+
+
+ // This is changed due to MS Windows doesn't support credentials in http uris
+ // so we detect them by regexp and strip off from result url
+ // Proof: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/a327cf3c-f033-4a54-8b7f-03c56ba3203f/windows-foundation-uri-security-problem
+
+ if (window.btoa) {
+ var credentials = getUrlCredentials(urlString);
+ if (credentials) {
+ var authHeader = "Authorization";
+ var authHeaderValue = "Basic " + window.btoa(credentials);
+
+ header = {
+ name : authHeader,
+ value : authHeaderValue
+ };
+ }
+ }
+
+ return header;
+}
+
+function checkURL(url) {
+ return url.indexOf(' ') === -1 ? true : false;
+}
+
+var idCounter = 0;
+
+var transfers = {};
+
+/**
+ * FileTransfer uploads a file to a remote server.
+ * @constructor
+ */
+var FileTransfer = function() {
+ this._id = ++idCounter;
+ this.onprogress = null; // optional callback
+};
+
+/**
+ * Given an absolute file path, uploads a file on the device to a remote server
+ * using a multipart HTTP request.
+ * @param filePath {String} Full path of the file on the device
+ * @param server {String} URL of the server to receive the file
+ * @param successCallback (Function} Callback to be invoked when upload has completed
+ * @param errorCallback {Function} Callback to be invoked upon error
+ * @param options {FileUploadOptions} Optional parameters such as file name and mimetype
+ * @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false
+ */
+FileTransfer.prototype.upload = function(filePath, server, successCallback, errorCallback, options) {
+ // check for arguments
+ argscheck.checkArgs('ssFFO*', 'FileTransfer.upload', arguments);
+
+ // Check if target URL doesn't contain spaces. If contains, it should be escaped first
+ // (see https://github.com/apache/cordova-plugin-file-transfer/blob/master/doc/index.md#upload)
+ if (!checkURL(server)) {
+ errorCallback && errorCallback(new FileTransferError(FileTransferError.INVALID_URL_ERR, filePath, server));
+ return;
+ }
+
+ options = options || {};
+
+ var fileKey = options.fileKey || "file";
+ var fileName = options.fileName || "image.jpg";
+ var mimeType = options.mimeType || "image/jpeg";
+ var params = options.params || {};
+ // var chunkedMode = !!options.chunkedMode; // Not supported
+ var headers = options.headers || {};
+ var httpMethod = options.httpMethod && options.httpMethod.toUpperCase() === "PUT" ? "PUT" : "POST";
+
+ var basicAuthHeader = getBasicAuthHeader(server);
+ if (basicAuthHeader) {
+ server = server.replace(getUrlCredentials(server) + '@', '');
+ headers[basicAuthHeader.name] = basicAuthHeader.value;
+ }
+
+ var that = this;
+ var xhr = transfers[this._id] = new XMLHttpRequest();
+
+ var fail = errorCallback && function(code, status, response) {
+ transfers[this._id] && delete transfers[this._id];
+ var error = new FileTransferError(code, filePath, server, status, response);
+ errorCallback && errorCallback(error);
+ };
+
+ window.resolveLocalFileSystemURL(filePath, function(entry) {
+ entry.file(function(file) {
+ var reader = new FileReader();
+ reader.onloadend = function() {
+ var blob = new Blob([this.result], {type: mimeType});
+
+ // Prepare form data to send to server
+ var fd = new FormData();
+ fd.append(fileKey, blob, fileName);
+ for (var prop in params) {
+ if (params.hasOwnProperty(prop)) {
+ fd.append(prop, params[prop]);
+ }
+ }
+
+ xhr.open(httpMethod, server);
+
+ // Fill XHR headers
+ for (var header in headers) {
+ if (headers.hasOwnProperty(header)) {
+ xhr.setRequestHeader(header, headers[header]);
+ }
+ }
+
+ xhr.onload = function() {
+ if (this.status === 200) {
+ var result = new FileUploadResult(); // jshint ignore:line
+ result.bytesSent = blob.size;
+ result.responseCode = this.status;
+ result.response = this.response;
+ delete transfers[that._id];
+ successCallback(result);
+ } else if (this.status === 404) {
+ fail(FileTransferError.INVALID_URL_ERR, this.status, this.response);
+ } else {
+ fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
+ }
+ };
+
+ xhr.ontimeout = function() {
+ fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
+ };
+
+ xhr.onerror = function() {
+ fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
+ };
+
+ xhr.onabort = function () {
+ fail(FileTransferError.ABORT_ERR, this.status, this.response);
+ };
+
+ xhr.upload.onprogress = function (e) {
+ that.onprogress && that.onprogress(e);
+ };
+
+ xhr.send(fd);
+ // Special case when transfer already aborted, but XHR isn't sent.
+ // In this case XHR won't fire an abort event, so we need to check if transfers record
+ // isn't deleted by filetransfer.abort and if so, call XHR's abort method again
+ if (!transfers[that._id]) {
+ xhr.abort();
+ }
+ };
+ reader.readAsArrayBuffer(file);
+ }, function() {
+ fail(FileTransferError.FILE_NOT_FOUND_ERR);
+ });
+ }, function() {
+ fail(FileTransferError.FILE_NOT_FOUND_ERR);
+ });
+};
+
+/**
+ * Downloads a file form a given URL and saves it to the specified directory.
+ * @param source {String} URL of the server to receive the file
+ * @param target {String} Full path of the file on the device
+ * @param successCallback (Function} Callback to be invoked when upload has completed
+ * @param errorCallback {Function} Callback to be invoked upon error
+ * @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false
+ * @param options {FileDownloadOptions} Optional parameters such as headers
+ */
+FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts, options) {
+ argscheck.checkArgs('ssFF*', 'FileTransfer.download', arguments);
+
+ // Check if target URL doesn't contain spaces. If contains, it should be escaped first
+ // (see https://github.com/apache/cordova-plugin-file-transfer/blob/master/doc/index.md#download)
+ if (!checkURL(source)) {
+ errorCallback && errorCallback(new FileTransferError(FileTransferError.INVALID_URL_ERR, source, target));
+ return;
+ }
+
+ options = options || {};
+
+ var headers = options.headers || {};
+
+ var basicAuthHeader = getBasicAuthHeader(source);
+ if (basicAuthHeader) {
+ source = source.replace(getUrlCredentials(source) + '@', '');
+ headers[basicAuthHeader.name] = basicAuthHeader.value;
+ }
+
+ var that = this;
+ var xhr = transfers[this._id] = new XMLHttpRequest();
+
+ 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
+ // but in case of error we need to raise event with plain text response
+ if (response instanceof Blob) {
+ var reader = new FileReader();
+ reader.readAsText(response);
+ reader.onloadend = function(e) {
+ var error = new FileTransferError(code, source, target, status, e.target.result);
+ errorCallback(error);
+ };
+ } else {
+ var error = new FileTransferError(code, source, target, status, response);
+ errorCallback(error);
+ }
+ };
+
+ xhr.onload = function (e) {
+
+ var fileNotFound = function () {
+ fail(FileTransferError.FILE_NOT_FOUND_ERR);
+ };
+
+ var req = e.target;
+ // req.status === 0 is special case for local files with file:// URI scheme
+ if ((req.status === 200 || req.status === 0) && req.response) {
+ window.resolveLocalFileSystemURL(getParentPath(target), function (dir) {
+ dir.getFile(getFileName(target), {create: true}, function writeFile(entry) {
+ entry.createWriter(function (fileWriter) {
+ fileWriter.onwriteend = function (evt) {
+ if (!evt.target.error) {
+ entry.filesystemName = entry.filesystem.name;
+ delete transfers[that._id];
+ successCallback && successCallback(entry);
+ } else {
+ fail(FileTransferError.FILE_NOT_FOUND_ERR);
+ }
+ };
+ fileWriter.onerror = function () {
+ fail(FileTransferError.FILE_NOT_FOUND_ERR);
+ };
+ fileWriter.write(req.response);
+ }, fileNotFound);
+ }, fileNotFound);
+ }, fileNotFound);
+ } else if (req.status === 404) {
+ fail(FileTransferError.INVALID_URL_ERR, req.status, req.response);
+ } else {
+ fail(FileTransferError.CONNECTION_ERR, req.status, req.response);
+ }
+ };
+
+ xhr.onprogress = function (e) {
+ that.onprogress && that.onprogress(e);
+ };
+
+ xhr.onerror = function () {
+ fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
+ };
+
+ xhr.onabort = function () {
+ fail(FileTransferError.ABORT_ERR, this.status, this.response);
+ };
+
+ xhr.open("GET", source, true);
+
+ for (var header in headers) {
+ if (headers.hasOwnProperty(header)) {
+ xhr.setRequestHeader(header, headers[header]);
+ }
+ }
+
+ xhr.responseType = "blob";
+
+ xhr.send();
+};
+
+/**
+ * Aborts the ongoing file transfer on this object. The original error
+ * callback for the file transfer will be called if necessary.
+ */
+FileTransfer.prototype.abort = function() {
+ if (this instanceof FileTransfer) {
+ if (transfers[this._id]) {
+ transfers[this._id].abort();
+ delete transfers[this._id];
+ }
+ }
+};
+
+module.exports = FileTransfer;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[04/13] cordova-plugin-file-transfer git commit: CB-8095 Updates
tests and documentation
Posted by pu...@apache.org.
CB-8095 Updates tests and documentation
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/320f0d41
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/320f0d41
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/320f0d41
Branch: refs/heads/master
Commit: 320f0d417369a908ea30250fa0c637e9243083f2
Parents: e781bce
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Thu Nov 27 18:50:01 2014 +0300
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:46:00 2015 -0800
----------------------------------------------------------------------
doc/index.md | 6 ++----
tests/tests.js | 12 ------------
2 files changed, 2 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/320f0d41/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 82b0d50..81710b1 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -42,15 +42,13 @@ Although in the global scope, they are not available until after the `deviceread
- Firefox OS**
- iOS
- Windows Phone 7 and 8*
-- Windows 8***
-- Windows***
+- Windows 8
+- Windows
\* _Do not support `onprogress` nor `abort()`_
\** _Do not support `onprogress`_
-\*** Partial support of `onprogress` for upload method. `onprogress` is called with empty progress event due to Windows limitations_
-
# FileTransfer
The `FileTransfer` object provides a way to upload files using an HTTP
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/320f0d41/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 240a83d..309a6c0 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -659,12 +659,6 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.18 should be able to upload a file", function (done) {
- // according to spec "onprogress" method isn't supported on WP
- if (isWP81()) {
- pending();
- return;
- }
-
var fileURL = SERVER + '/upload';
var uploadWin = function (uploadResult) {
@@ -685,12 +679,6 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.19 should be able to upload a file with http basic auth", function (done) {
- // according to spec "onprogress" method doesn't supported on WP
- if (isWP81()) {
- pending();
- return;
- }
-
var fileURL = SERVER_WITH_CREDENTIALS + "/upload_basic_auth";
var uploadWin = function (uploadResult) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[09/13] cordova-plugin-file-transfer git commit: CB-8407 Use File
proxy to construct valid FileEntry for download success callback
Posted by pu...@apache.org.
CB-8407 Use File proxy to construct valid FileEntry for download success callback
Due to changes in file plugin (https://github.com/apache/cordova-plugin-file/commit/bcbeae24cd24583b790da95e0e076492eb16cd4f) result of download method should now have filesystemName specified for proper work. This updates download method to construct FileEntry properly, using File plugin proxy.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/5ee666ce
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/5ee666ce
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/5ee666ce
Branch: refs/heads/master
Commit: 5ee666ce0b65fcde396e45974795a86f1097e5bc
Parents: 28189e5
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Tue Feb 3 17:06:14 2015 +0300
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:46:03 2015 -0800
----------------------------------------------------------------------
src/windows/FileTransferProxy.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/5ee666ce/src/windows/FileTransferProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js
index 2649282..df5dd0a 100644
--- a/src/windows/FileTransferProxy.js
+++ b/src/windows/FileTransferProxy.js
@@ -26,6 +26,7 @@
var FTErr = require('./FileTransferError'),
ProgressEvent = require('org.apache.cordova.file.ProgressEvent'),
FileUploadResult = require('org.apache.cordova.file.FileUploadResult'),
+ FileProxy = require('org.apache.cordova.file.FileProxy'),
FileEntry = require('org.apache.cordova.file.FileEntry');
var appData = Windows.Storage.ApplicationData.current;
@@ -313,7 +314,9 @@ exec(win, fail, 'FileTransfer', 'upload',
.replace(appData.temporaryFolder.path, 'ms-appdata:///temp')
.replace('\\', '/');
- successCallback(new FileEntry(storageFile.name, storageFile.path, null, nativeURI));
+ // Passing null as error callback here because downloaded file should exist in any case
+ // otherwise the error callback will be hit during file creation in another place
+ FileProxy.resolveLocalFileSystemURI(successCallback, null, [nativeURI]);
}, function(error) {
var getTransferError = new WinJS.Promise(function (resolve) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[13/13] cordova-plugin-file-transfer git commit: Merge branch
'master' of
https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer
Posted by pu...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/49c21f95
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/49c21f95
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/49c21f95
Branch: refs/heads/master
Commit: 49c21f951f51381d887646b38823222ed11c60c1
Parents: d8f7545 9269172
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Wed Feb 11 17:47:59 2015 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:47:59 2015 -0800
----------------------------------------------------------------------
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[12/13] cordova-plugin-file-transfer git commit: CB-8429 Incremented
plugin version.
Posted by pu...@apache.org.
CB-8429 Incremented plugin version.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/d8f75455
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/d8f75455
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/d8f75455
Branch: refs/heads/master
Commit: d8f75455267137fc0122d759e747b88ea4bf9733
Parents: e0f9aad
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Feb 9 09:59:59 2015 -0500
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:46:05 2015 -0800
----------------------------------------------------------------------
plugin.xml | 2 +-
tests/plugin.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/d8f75455/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 51f22e5..46868cf 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -21,7 +21,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.file-transfer"
- version="0.5.0">
+ version="0.5.1-dev">
<name>File Transfer</name>
<description>Cordova File Transfer Plugin</description>
<license>Apache 2.0</license>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/d8f75455/tests/plugin.xml
----------------------------------------------------------------------
diff --git a/tests/plugin.xml b/tests/plugin.xml
index 5138b49..d3c1f8f 100644
--- a/tests/plugin.xml
+++ b/tests/plugin.xml
@@ -21,7 +21,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.file-transfer.tests"
- version="0.5.0">
+ version="0.5.1-dev">
<name>Cordova File Transfer Plugin Tests</name>
<license>Apache 2.0</license>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[07/13] cordova-plugin-file-transfer git commit: CB-8429 Incremented
plugin version.
Posted by pu...@apache.org.
CB-8429 Incremented plugin version.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/976275e9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/976275e9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/976275e9
Branch: refs/heads/master
Commit: 976275e955d48d0e06cee7b1e7e157d7585933a4
Parents: e680c78
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Feb 4 20:54:02 2015 -0500
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:46:02 2015 -0800
----------------------------------------------------------------------
plugin.xml | 2 +-
tests/plugin.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/976275e9/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 51f22e5..46868cf 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -21,7 +21,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.file-transfer"
- version="0.5.0">
+ version="0.5.1-dev">
<name>File Transfer</name>
<description>Cordova File Transfer Plugin</description>
<license>Apache 2.0</license>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/976275e9/tests/plugin.xml
----------------------------------------------------------------------
diff --git a/tests/plugin.xml b/tests/plugin.xml
index 5138b49..d3c1f8f 100644
--- a/tests/plugin.xml
+++ b/tests/plugin.xml
@@ -21,7 +21,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.file-transfer.tests"
- version="0.5.0">
+ version="0.5.1-dev">
<name>Cordova File Transfer Plugin Tests</name>
<license>Apache 2.0</license>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[10/13] cordova-plugin-file-transfer git commit: Fixes typo,
introduced in
https://github.com/apache/cordova-plugin-file-transfer/commit/bc43b46
Posted by pu...@apache.org.
Fixes typo, introduced in https://github.com/apache/cordova-plugin-file-transfer/commit/bc43b46
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/314677c0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/314677c0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/314677c0
Branch: refs/heads/master
Commit: 314677c0c3604a805a5cc1b8ccb11cc2582c8709
Parents: 5ee666c
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Fri Feb 6 14:53:57 2015 +0300
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:46:04 2015 -0800
----------------------------------------------------------------------
src/windows/FileTransferProxy.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/314677c0/src/windows/FileTransferProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js
index df5dd0a..3d299ef 100644
--- a/src/windows/FileTransferProxy.js
+++ b/src/windows/FileTransferProxy.js
@@ -281,7 +281,7 @@ exec(win, fail, 'FileTransfer', 'upload',
// if download isn't cancelled, contunue with creating and preparing download operation
var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader();
for (var header in headers) {
- if (header.hasOwnProperty(header)) {
+ if (headers.hasOwnProperty(header)) {
downloader.setRequestHeader(header, headers[header]);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[11/13] cordova-plugin-file-transfer git commit: CB-8429 Updated
version and RELEASENOTES.md for release 0.5.0 (take 2)
Posted by pu...@apache.org.
CB-8429 Updated version and RELEASENOTES.md for release 0.5.0 (take 2)
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/e0f9aad3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/e0f9aad3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/e0f9aad3
Branch: refs/heads/master
Commit: e0f9aad374adb5942b491c3b34bcd89937f905c3
Parents: 314677c
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Feb 9 09:57:48 2015 -0500
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:46:04 2015 -0800
----------------------------------------------------------------------
RELEASENOTES.md | 1 +
plugin.xml | 2 +-
tests/plugin.xml | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/e0f9aad3/RELEASENOTES.md
----------------------------------------------------------------------
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
index 6389fab..40a4ccf 100644
--- a/RELEASENOTES.md
+++ b/RELEASENOTES.md
@@ -145,6 +145,7 @@
* CB-7700 cordova-plugin-file-transfer documentation translation: cordova-plugin-file-transfer
### 0.5.0 (Feb 04, 2015)
+* CB-8407 windows: Fix download of `ms-appdata:///` URIs
* CB-8095 windows: Rewrite upload method to support progress events properly
* CB-5059 android: Add a CookieManager abstraction for pluggable webviews
* ios: Fix compile warning about implicity int conversion
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/e0f9aad3/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 46868cf..51f22e5 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -21,7 +21,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.file-transfer"
- version="0.5.1-dev">
+ version="0.5.0">
<name>File Transfer</name>
<description>Cordova File Transfer Plugin</description>
<license>Apache 2.0</license>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/e0f9aad3/tests/plugin.xml
----------------------------------------------------------------------
diff --git a/tests/plugin.xml b/tests/plugin.xml
index d3c1f8f..5138b49 100644
--- a/tests/plugin.xml
+++ b/tests/plugin.xml
@@ -21,7 +21,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.file-transfer.tests"
- version="0.5.1-dev">
+ version="0.5.0">
<name>Cordova File Transfer Plugin Tests</name>
<license>Apache 2.0</license>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[03/13] cordova-plugin-file-transfer git commit: CB-8095 Fixes JSHint
and formatting issues
Posted by pu...@apache.org.
CB-8095 Fixes JSHint and formatting issues
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/837771c4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/837771c4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/837771c4
Branch: refs/heads/master
Commit: 837771c4c6d460c7c9df1b729a4a4c1d2b76755a
Parents: 320f0d4
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Thu Jan 8 16:28:45 2015 +0300
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:46:00 2015 -0800
----------------------------------------------------------------------
src/windows/FileTransferProxy.js | 25 ++++++--------
tests/tests.js | 64 ++++++++++++++++++++---------------
2 files changed, 47 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/837771c4/src/windows/FileTransferProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js
index 5211464..453b02b 100644
--- a/src/windows/FileTransferProxy.js
+++ b/src/windows/FileTransferProxy.js
@@ -20,6 +20,8 @@
*/
/*jshint -W030 */
+/*global Windows, WinJS*/
+/*global module, require*/
var FTErr = require('./FileTransferError'),
ProgressEvent = require('org.apache.cordova.file.ProgressEvent'),
@@ -71,17 +73,17 @@ exec(win, fail, 'FileTransfer', 'upload',
var fileName = options[3];
var mimeType = options[4];
var params = options[5];
- var trustAllHosts = options[6]; // todo
- var chunkedMode = options[7]; // todo
+ // var trustAllHosts = options[6]; // todo
+ // var chunkedMode = options[7]; // todo
var headers = options[8] || {};
var uploadId = options[9];
- if (!filePath || (typeof filePath != 'string')) {
+ if (!filePath || (typeof filePath !== 'string')) {
errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR,null,server));
return;
}
- if (filePath.substr(0, 8) == "file:///") {
+ if (filePath.substr(0, 8) === "file:///") {
filePath = appData.localFolder.path + filePath.substr(8).split("/").join("\\");
} else if (filePath.indexOf('ms-appdata:///') === 0) {
// Handle 'ms-appdata' scheme
@@ -143,7 +145,6 @@ exec(win, fail, 'FileTransfer', 'upload',
try {
uploader.createUploadAsync(uri, transferParts).then(
function (upload) {
-
// update internal TransferOperation object with newly created promise
var uploadOperation = upload.startAsync();
fileTransferOps[uploadId].promise = uploadOperation;
@@ -169,7 +170,6 @@ exec(win, fail, 'FileTransfer', 'upload',
});
},
function (error) {
-
var source = nativePathToCordova(filePath);
// Handle download error here.
@@ -208,12 +208,8 @@ exec(win, fail, 'FileTransfer', 'upload',
errorCallback(transferError);
});
});
-
-
},
function (evt) {
-
-
var progressEvent = new ProgressEvent('progress', {
loaded: evt.progress.bytesSent,
total: evt.progress.totalBytesToSend,
@@ -223,7 +219,6 @@ exec(win, fail, 'FileTransfer', 'upload',
successCallback(progressEvent, { keepCallback: true });
}
);
-
},
function (err) {
var errorObj = new FTErr(FTErr.INVALID_URL_ERR);
@@ -250,7 +245,7 @@ exec(win, fail, 'FileTransfer', 'upload',
errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR));
return;
}
- if (target.substr(0, 8) == "file:///") {
+ if (target.substr(0, 8) === "file:///") {
target = appData.localFolder.path + target.substr(8).split("/").join("\\");
} else if (target.indexOf('ms-appdata:///') === 0) {
// Handle 'ms-appdata' scheme
@@ -276,7 +271,7 @@ exec(win, fail, 'FileTransfer', 'upload',
// check if download isn't already cancelled
var downloadOp = fileTransferOps[downloadId];
- if (downloadOp && downloadOp.state == FileTransferOperation.CANCELLED) {
+ if (downloadOp && downloadOp.state === FileTransferOperation.CANCELLED) {
// Here we should call errorCB with ABORT_ERR error
errorCallback(new FTErr(FTErr.ABORT_ERR, source, target));
return;
@@ -285,7 +280,9 @@ exec(win, fail, 'FileTransfer', 'upload',
// if download isn't cancelled, contunue with creating and preparing download operation
var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader();
for (var header in headers) {
- downloader.setRequestHeader(header, headers[header]);
+ if (header.hasOwnProperty(header)) {
+ downloader.setRequestHeader(header, headers[header]);
+ }
}
// create download object. This will throw an exception if URL is malformed
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/837771c4/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 309a6c0..f64a4b0 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -19,10 +19,15 @@
*
*/
+/* global exports, cordova */
+/* global describe, it, expect, beforeEach, afterEach, jasmine, pending, spyOn */
+
+/* global FileTransfer, FileTransferError, FileUploadOptions, LocalFileSystem */
+
exports.defineAutoTests = function () {
// constants
- var GRACE_TIME_DELTA = 300 // in milliseconds
+ var GRACE_TIME_DELTA = 300; // in milliseconds
var UNKNOWN_HOST = "http://foobar.apache.org";
var HEADERS_ECHO = "http://whatheaders.com"; // NOTE: this site is very useful!
@@ -34,11 +39,7 @@ exports.defineAutoTests = function () {
// flags
var isWindows = function() {
- return (cordova.platformId == "windows") || (navigator.appVersion.indexOf("MSAppHost/1.0") !== -1);
- };
-
- var isWP81 = function() {
- return navigator.appVersion.indexOf("Windows Phone 8.1;") !== -1;
+ return (cordova.platformId === "windows") || (navigator.appVersion.indexOf("MSAppHost/1.0") !== -1);
};
describe('FileTransferError', function () {
@@ -126,7 +127,7 @@ exports.defineAutoTests = function () {
function (fileEntry) {
fileEntry.createWriter(function (writer) {
- writer.onwrite = function (evt) {
+ writer.onwrite = function () {
console.log('created test file \'' + name + '\'');
success(fileEntry);
};
@@ -202,21 +203,27 @@ exports.defineAutoTests = function () {
beforeEach(function() {
// ignore the actual implementations of the unexpected callbacks
- for (callback in unexpectedCallbacks) {
- spyOn(unexpectedCallbacks, callback);
+ for (var callback in unexpectedCallbacks) {
+ if (unexpectedCallbacks.hasOwnProperty(callback)) {
+ spyOn(unexpectedCallbacks, callback);
+ }
}
// but run the implementations of the expected callbacks
for (callback in expectedCallbacks) {
- spyOn(expectedCallbacks, callback).and.callThrough();
+ if (expectedCallbacks.hasOwnProperty(callback)) {
+ spyOn(expectedCallbacks, callback).and.callThrough();
+ }
}
});
// at the end, check that none of the unexpected callbacks got called,
// and act on the expected callbacks
afterEach(function() {
- for (callback in unexpectedCallbacks) {
- expect(unexpectedCallbacks[callback]).not.toHaveBeenCalled();
+ for (var callback in unexpectedCallbacks) {
+ if (unexpectedCallbacks.hasOwnProperty(callback)) {
+ expect(unexpectedCallbacks[callback]).not.toHaveBeenCalled();
+ }
}
if (expectedCallbacks.unsupportedOperation.calls.any()) {
@@ -380,7 +387,7 @@ exports.defineAutoTests = function () {
var reader = new FileReader();
reader.onerror = unexpectedCallbacks.fileOperationFail;
- reader.onload = function (e) {
+ reader.onload = function () {
expect(reader.result).toMatch(/The Apache Software Foundation/);
done();
};
@@ -607,6 +614,7 @@ exports.defineAutoTests = function () {
var uploadOptions;
var fileName;
+ var fileContents;
var localFilePath;
// helpers
@@ -633,7 +641,7 @@ exports.defineAutoTests = function () {
fileName = 'fileToUpload.txt';
fileContents = 'upload test file';
- uploadParams = new Object();
+ uploadParams = {};
uploadParams.value1 = "test";
uploadParams.value2 = "param";
@@ -646,7 +654,7 @@ exports.defineAutoTests = function () {
var fileWin = function (entry) {
localFilePath = entry.toURL();
done();
- }
+ };
// create a file to upload
writeFile(root, fileName, fileContents, fileWin);
@@ -665,7 +673,7 @@ exports.defineAutoTests = function () {
verifyUpload(uploadResult);
- if (cordova.platformId == 'ios') {
+ if (cordova.platformId === 'ios') {
expect(uploadResult.headers).toBeDefined('Expected headers to be defined.');
expect(uploadResult.headers['Content-Type']).toBeDefined('Expected content-type header to be defined.');
}
@@ -703,7 +711,7 @@ exports.defineAutoTests = function () {
setTimeout(done, GRACE_TIME_DELTA * 2);
};
- var fileWin = function (fileEntry) {
+ var fileWin = function () {
startTime = +new Date();
@@ -859,7 +867,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
var videoURL = "http://techslides.com/demos/sample-videos/small.mp4";
function clearResults() {
- results = document.getElementById("info");
+ var results = document.getElementById("info");
results.innerHTML = '';
}
@@ -870,8 +878,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
var ft = new FileTransfer();
console.log("Starting download");
ft.download(source, fileSystem.root.toURL() + filename, function (entry) {
- console.log("Download complete")
- element.src = urlFn(entry)
+ console.log("Download complete");
+ element.src = urlFn(entry);
console.log("Src URL is " + element.src);
console.log("Inserting element");
document.getElementById("info").appendChild(element);
@@ -879,14 +887,14 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}
console.log("Requesting filesystem");
clearResults();
- requestFileSystem(TEMPORARY, 0, function (fileSystem) {
+ window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fileSystem) {
console.log("Checking for existing file");
- if (directory != undefined) {
+ if (directory !== undefined) {
console.log("Checking for existing directory.");
fileSystem.root.getDirectory(directory, {}, function (dirEntry) {
dirEntry.removeRecursively(function () {
download(fileSystem);
- }, function (e) { console.log("ERROR: dirEntry.removeRecursively") });
+ }, function () { console.log("ERROR: dirEntry.removeRecursively"); });
}, function () {
download(fileSystem);
});
@@ -895,12 +903,12 @@ exports.defineManualTests = function (contentEl, createActionButton) {
console.log("Removing existing file");
entry.remove(function () {
download(fileSystem);
- }, function (e) { console.log("ERROR: entry.remove"); });
+ }, function () { console.log("ERROR: entry.remove"); });
}, function () {
download(fileSystem);
});
}
- }, function (e) { console.log("ERROR: requestFileSystem"); });
+ }, function () { console.log("ERROR: requestFileSystem"); });
}
/******************************************************************************/
@@ -923,11 +931,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}, 'cdv_image');
createActionButton('Download and display img (native)', function () {
- downloadImg(imageURL, function (entry) { return entry.toNativeURL(); }, new Image);
+ downloadImg(imageURL, function (entry) { return entry.toNativeURL(); }, new Image());
}, 'native_image');
createActionButton('Download to a non-existent dir (should work)', function () {
- downloadImg(imageURL, function (entry) { return entry.toURL(); }, new Image, '/nonExistentDirTest/');
+ downloadImg(imageURL, function (entry) { return entry.toURL(); }, new Image(), '/nonExistentDirTest/');
}, 'non-existent_dir');
createActionButton('Download and play video (cdvfile)', function () {
@@ -939,6 +947,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
createActionButton('Download and play video (native)', function () {
var videoElement = document.createElement('video');
videoElement.controls = "controls";
- downloadImg(videoURL, function (entry) { return entry.toNativeURL(); }, videoElement)
+ downloadImg(videoURL, function (entry) { return entry.toNativeURL(); }, videoElement);
}, 'native_video');
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[08/13] cordova-plugin-file-transfer git commit: CB-8407 Removes
excess path to native path conversion in download method
Posted by pu...@apache.org.
CB-8407 Removes excess path to native path conversion in download method
This fixes file transfer download tests failures, when target file is specified by ms-appdata:/// uri on Windows.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/28189e54
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/28189e54
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/28189e54
Branch: refs/heads/master
Commit: 28189e54f38bc61d4f28b117dfee6d9521f3bf3c
Parents: 976275e
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Tue Feb 3 15:50:31 2015 +0300
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:46:03 2015 -0800
----------------------------------------------------------------------
src/windows/FileTransferProxy.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/28189e54/src/windows/FileTransferProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js
index 453b02b..2649282 100644
--- a/src/windows/FileTransferProxy.js
+++ b/src/windows/FileTransferProxy.js
@@ -237,7 +237,7 @@ exec(win, fail, 'FileTransfer', 'upload',
// [source, target, trustAllHosts, id, headers]
download:function(successCallback, errorCallback, options) {
var source = options[0];
- var target = cordovaPathToNative(options[1]);
+ var target = options[1];
var downloadId = options[3];
var headers = options[4] || {};
@@ -252,7 +252,7 @@ exec(win, fail, 'FileTransfer', 'upload',
target = target.replace('ms-appdata:///local', appData.localFolder.path)
.replace('ms-appdata:///temp', appData.temporaryFolder.path);
}
- target = cordovaPathToNative(target); // again?
+ target = cordovaPathToNative(target);
var path = target.substr(0, target.lastIndexOf("\\"));
var fileName = target.substr(target.lastIndexOf("\\") + 1);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[02/13] cordova-plugin-file-transfer git commit: CB-8095 Rewrite
upload method to support progress events properly
Posted by pu...@apache.org.
CB-8095 Rewrite upload method to support progress events properly
* Uses backgroundUploader class instead of XHR
* Returns proper response body in case of error
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/e781bceb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/e781bceb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/e781bceb
Branch: refs/heads/master
Commit: e781bceba7763a44f344e43f0d31e16e0d8ea1be
Parents: 0aae944
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Thu Nov 27 18:49:13 2014 +0300
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:45:59 2015 -0800
----------------------------------------------------------------------
src/windows/FileTransferProxy.js | 163 +++++++++++++++++++++++++---------
1 file changed, 121 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/e781bceb/src/windows/FileTransferProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js
index 57c9ccd..5211464 100644
--- a/src/windows/FileTransferProxy.js
+++ b/src/windows/FileTransferProxy.js
@@ -106,55 +106,134 @@ exec(win, fail, 'FileTransfer', 'upload',
mimeType = storageFile.contentType;
}
- storageFile.openAsync(Windows.Storage.FileAccessMode.read)
- .then(function (stream) {
+ // check if download isn't already cancelled
+ var uploadOp = fileTransferOps[uploadId];
+ if (uploadOp && uploadOp.state === FileTransferOperation.CANCELLED) {
+ // Here we should call errorCB with ABORT_ERR error
+ errorCallback(new FTErr(FTErr.ABORT_ERR, nativePathToCordova(filePath), server));
+ return;
+ }
- // check if upload isn't already cancelled
- var uploadOp = fileTransferOps[uploadId];
- if (uploadOp && uploadOp.state == FileTransferOperation.CANCELLED) {
- // Here we should call errorCB with ABORT_ERR error
- errorCallback(new FTErr(FTErr.ABORT_ERR, filePath, server));
- return;
+ // setting request headers for uploader
+ var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();
+ for (var header in headers) {
+ if (headers.hasOwnProperty(header)) {
+ uploader.setRequestHeader(header, headers[header]);
}
+ }
- var blob = MSApp.createBlobFromRandomAccessStream(mimeType, stream);
-
- var formData = new FormData();
- formData.append(fileKey, blob, fileName);
- // add params
- for(var key in params) {
- formData.append(key,params[key]);
+ // adding params supplied to request payload
+ var transferParts = [];
+ for (var key in params) {
+ if (params.hasOwnProperty(key)) {
+ var contentPart = new Windows.Networking.BackgroundTransfer.BackgroundTransferContentPart();
+ contentPart.setHeader("Content-Disposition", "form-data; name=\"" + key + "\"");
+ contentPart.setText(params[key]);
+ transferParts.push(contentPart);
}
+ }
- var uploadOperation;
- try {
- // Create XHR promise for uploading data to server
- uploadOperation = WinJS.xhr({ type: "POST", url: server, data: formData, headers: headers });
- fileTransferOps[uploadId].promise = uploadOperation;
- } catch (e) {
- // it will fail if URL is malformed, so we handle this situation
- errorCallback(new FTErr(FTErr.INVALID_URL_ERR, filePath, server, null, null, e));
- return;
- }
+ // Adding file to upload to request payload
+ var fileToUploadPart = new Windows.Networking.BackgroundTransfer.BackgroundTransferContentPart(fileKey, fileName);
+ fileToUploadPart.setFile(storageFile);
+ transferParts.push(fileToUploadPart);
+
+ // create download object. This will throw an exception if URL is malformed
+ var uri = new Windows.Foundation.Uri(server);
+ try {
+ uploader.createUploadAsync(uri, transferParts).then(
+ function (upload) {
+
+ // update internal TransferOperation object with newly created promise
+ var uploadOperation = upload.startAsync();
+ fileTransferOps[uploadId].promise = uploadOperation;
+
+ uploadOperation.then(
+ function (result) {
+ // Update TransferOperation object with new state, delete promise property
+ // since it is not actual anymore
+ var currentUploadOp = fileTransferOps[uploadId];
+ if (currentUploadOp) {
+ currentUploadOp.state = FileTransferOperation.DONE;
+ currentUploadOp.promise = null;
+ }
+
+ var response = result.getResponseInformation();
+ // creating a data reader, attached to response stream to get server's response
+ var reader = new Windows.Storage.Streams.DataReader(result.getResultStreamAt(0));
+ reader.loadAsync(result.progress.bytesReceived).then(function(size) {
+ var responseText = reader.readString(size);
+ var ftResult = new FileUploadResult(size, response.statusCode, responseText);
+ successCallback(ftResult);
+ reader.close();
+ });
+ },
+ function (error) {
+
+ var source = nativePathToCordova(filePath);
+
+ // Handle download error here.
+ // Wrap this routines into promise due to some async methods
+ var getTransferError = new WinJS.Promise(function(resolve) {
+ if (error.message === 'Canceled') {
+ // If download was cancelled, message property will be specified
+ resolve(new FTErr(FTErr.ABORT_ERR, source, server, null, null, error));
+ } else {
+ // in the other way, try to get response property
+ var response = upload.getResponseInformation();
+ if (!response) {
+ resolve(new FTErr(FTErr.CONNECTION_ERR, source, server));
+ } else {
+ var reader = new Windows.Storage.Streams.DataReader(upload.getResultStreamAt(0));
+ reader.loadAsync(upload.progress.bytesReceived).then(function (size) {
+ var responseText = reader.readString(size);
+ resolve(new FTErr(FTErr.FILE_NOT_FOUND_ERR, source, server, response.statusCode, responseText, error));
+ reader.close();
+ });
+ }
+ }
+ });
- uploadOperation.then(function (response) {
- storageFile.getBasicPropertiesAsync().done(function(basicProperties) {
- var ftResult = new FileUploadResult(basicProperties.size, response.status, response.responseText);
- successCallback(ftResult);
- });
- }, function(err) {
- if ('status' in err) {
- errorCallback(new FTErr(FTErr.CONNECTION_ERR, filePath, server, err.status, err.responseText, err));
- } else {
- errorCallback(new FTErr(FTErr.INVALID_URL_ERR, filePath, server, null, null, err));
+ // Update TransferOperation object with new state, delete promise property
+ // since it is not actual anymore
+ var currentUploadOp = fileTransferOps[uploadId];
+ if (currentUploadOp) {
+ currentUploadOp.state = FileTransferOperation.CANCELLED;
+ currentUploadOp.promise = null;
+ }
+
+ // Cleanup, remove incompleted file
+ getTransferError.then(function(transferError) {
+ storageFile.deleteAsync().then(function() {
+ errorCallback(transferError);
+ });
+ });
+
+
+ },
+ function (evt) {
+
+
+ var progressEvent = new ProgressEvent('progress', {
+ loaded: evt.progress.bytesSent,
+ total: evt.progress.totalBytesToSend,
+ target: evt.resultFile
+ });
+ progressEvent.lengthComputable = true;
+ successCallback(progressEvent, { keepCallback: true });
+ }
+ );
+
+ },
+ function (err) {
+ var errorObj = new FTErr(FTErr.INVALID_URL_ERR);
+ errorObj.exception = err;
+ errorCallback(errorObj);
}
- }, function(evt) {
- // progress event handler, calls successCallback with empty ProgressEvent
- // We can't specify ProgressEvent data here since evt not provides any helpful information
- var progressEvent = new ProgressEvent('progress');
- successCallback(progressEvent, { keepCallback: true });
- });
- });
+ );
+ } catch (e) {
+ errorCallback(new FTErr(FTErr.INVALID_URL_ERR));
+ }
}, function(err) {
errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR, server, server, null, null, err));
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[05/13] cordova-plugin-file-transfer git commit: CB-8429 Updated
version and RELEASENOTES.md for release 0.5.0
Posted by pu...@apache.org.
CB-8429 Updated version and RELEASENOTES.md for release 0.5.0
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/e680c783
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/e680c783
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/e680c783
Branch: refs/heads/master
Commit: e680c783d3d1d719dc6a275c07c3366425938f62
Parents: bb0ed70
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Feb 4 20:12:45 2015 -0500
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Feb 11 17:46:01 2015 -0800
----------------------------------------------------------------------
RELEASENOTES.md | 13 +++++++++++++
plugin.xml | 2 +-
tests/plugin.xml | 2 +-
3 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/e680c783/RELEASENOTES.md
----------------------------------------------------------------------
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
index 2bbe78b..6389fab 100644
--- a/RELEASENOTES.md
+++ b/RELEASENOTES.md
@@ -143,3 +143,16 @@
* CB-7944 Pended unsupported auto tests for *Windows*
* CB-7977 Mention `deviceready` in plugin docs
* CB-7700 cordova-plugin-file-transfer documentation translation: cordova-plugin-file-transfer
+
+### 0.5.0 (Feb 04, 2015)
+* CB-8095 windows: Rewrite upload method to support progress events properly
+* CB-5059 android: Add a CookieManager abstraction for pluggable webviews
+* ios: Fix compile warning about implicity int conversion
+* CB-8351 ios: Use argumentForIndex rather than NSArray extension
+* CB-8351 ios: Use a local copy of DLog macro rather than CordovaLib version
+* CB-8296 ios: Fix crash when upload fails and file is not yet created (close #57)
+* Document "body" property on FileTransferError
+* CB-7912 ios, android: Update to work with whitelist plugins in Cordova 4.x
+* Error callback should always be called with the FileTransferError object, and not just the code
+* windows: alias appData to Windows.Storage.ApplicationData.current
+* CB-8093 Fixes incorrect FileTransferError returned in case of download failure
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/e680c783/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index cb85a32..51f22e5 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -21,7 +21,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.file-transfer"
- version="0.4.9-dev">
+ version="0.5.0">
<name>File Transfer</name>
<description>Cordova File Transfer Plugin</description>
<license>Apache 2.0</license>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/e680c783/tests/plugin.xml
----------------------------------------------------------------------
diff --git a/tests/plugin.xml b/tests/plugin.xml
index 0f09de3..5138b49 100644
--- a/tests/plugin.xml
+++ b/tests/plugin.xml
@@ -21,7 +21,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.file-transfer.tests"
- version="0.4.9-dev">
+ version="0.5.0">
<name>Cordova File Transfer Plugin Tests</name>
<license>Apache 2.0</license>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org