mirror of
https://github.com/apache/cordova-plugin-file-transfer.git
synced 2026-04-28 00:02:49 +08:00
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
<!--
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
-->
|
||||||
|
# Release Notes
|
||||||
|
|
||||||
|
|
||||||
+1
-12
@@ -1,9 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="org.apache.cordova.core.file-transfer"
|
id="org.apache.cordova.core.file-transfer"
|
||||||
version="0.2.0">
|
version="0.3.1-dev">
|
||||||
<name>File Transfer</name>
|
<name>File Transfer</name>
|
||||||
<description>Cordova File Transfer Plugin</description>
|
<description>Cordova File Transfer Plugin</description>
|
||||||
<license>Apache 2.0</license>
|
<license>Apache 2.0</license>
|
||||||
@@ -68,11 +67,6 @@
|
|||||||
</config-file>
|
</config-file>
|
||||||
|
|
||||||
<source-file src="src/wp/FileTransfer.cs" />
|
<source-file src="src/wp/FileTransfer.cs" />
|
||||||
|
|
||||||
<js-module src="www/wp/FileTransfer.js" name="FileTransfer1">
|
|
||||||
<clobbers target="window.FileTransfer" />
|
|
||||||
</js-module>
|
|
||||||
|
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<!-- wp8 -->
|
<!-- wp8 -->
|
||||||
@@ -84,11 +78,6 @@
|
|||||||
</config-file>
|
</config-file>
|
||||||
|
|
||||||
<source-file src="src/wp/FileTransfer.cs" />
|
<source-file src="src/wp/FileTransfer.cs" />
|
||||||
|
|
||||||
<js-module src="www/wp/FileTransfer.js" name="FileTransfer1">
|
|
||||||
<clobbers target="window.FileTransfer" />
|
|
||||||
</js-module>
|
|
||||||
|
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<!-- windows8 -->
|
<!-- windows8 -->
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
@@ -326,7 +326,7 @@ namespace WPCordovaClassLib.Cordova.Commands
|
|||||||
string[] strHeaders = temp.Split(',');
|
string[] strHeaders = temp.Split(',');
|
||||||
for (int n = 0; n < strHeaders.Length; n++)
|
for (int n = 0; n < strHeaders.Length; n++)
|
||||||
{
|
{
|
||||||
string[] split = strHeaders[n].Split(':');
|
string[] split = strHeaders[n].Split(":".ToCharArray(), 2);
|
||||||
if (split.Length == 2)
|
if (split.Length == 2)
|
||||||
{
|
{
|
||||||
split[0] = JSON.JsonHelper.Deserialize<string>(split[0]);
|
split[0] = JSON.JsonHelper.Deserialize<string>(split[0]);
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
var exec = require('cordova/exec'),
|
|
||||||
FileTransferError = require('cordova/plugin/FileTransferError');
|
|
||||||
|
|
||||||
// Note that the only difference between this and the default implementation is the
|
|
||||||
// object literal passed to exec() in upload - jm
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FileTransfer uploads a file to a remote server.
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
var FileTransfer = function() {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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, trustAllHosts) {
|
|
||||||
|
|
||||||
// sanity parameter checking
|
|
||||||
if (!filePath || !server) throw new Error("FileTransfer.upload requires filePath and server URL parameters at the minimum.");
|
|
||||||
// check for options
|
|
||||||
var fileKey = null;
|
|
||||||
var fileName = null;
|
|
||||||
var mimeType = null;
|
|
||||||
var params = null;
|
|
||||||
var chunkedMode = true;
|
|
||||||
|
|
||||||
if (options) {
|
|
||||||
fileKey = options.fileKey;
|
|
||||||
fileName = options.fileName;
|
|
||||||
mimeType = options.mimeType;
|
|
||||||
if (options.chunkedMode !== null || typeof options.chunkedMode != "undefined") {
|
|
||||||
chunkedMode = options.chunkedMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if options are specified, and NOT a string already, we will stringify it.
|
|
||||||
if(options.params && typeof options.params != typeof "") {
|
|
||||||
var arrParams = [];
|
|
||||||
for(var v in options.params) {
|
|
||||||
arrParams.push(v + "=" + options.params[v]);
|
|
||||||
}
|
|
||||||
params = encodeURI(arrParams.join("&"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var fail = function(e) {
|
|
||||||
var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
|
|
||||||
errorCallback(error);
|
|
||||||
};
|
|
||||||
exec(successCallback, fail, 'FileTransfer', 'upload', [{"filePath":filePath,
|
|
||||||
"server":server,
|
|
||||||
"fileKey":fileKey,
|
|
||||||
"fileName":fileName,
|
|
||||||
"mimeType":mimeType,
|
|
||||||
"params":params,
|
|
||||||
"trustAllHosts":trustAllHosts,
|
|
||||||
"chunkedMode":chunkedMode}]);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
FileTransfer.prototype.download = function(source, target, successCallback, errorCallback) {
|
|
||||||
// sanity parameter checking
|
|
||||||
if (!source || !target) throw new Error("FileTransfer.download requires source URI and target URI parameters at the minimum.");
|
|
||||||
var win = function(result) {
|
|
||||||
var entry = null;
|
|
||||||
if (result.isDirectory) {
|
|
||||||
entry = new (require('cordova/plugin/DirectoryEntry'))();
|
|
||||||
}
|
|
||||||
else if (result.isFile) {
|
|
||||||
entry = new (require('cordova/plugin/FileEntry'))();
|
|
||||||
}
|
|
||||||
entry.isDirectory = result.isDirectory;
|
|
||||||
entry.isFile = result.isFile;
|
|
||||||
entry.name = result.name;
|
|
||||||
entry.fullPath = result.fullPath;
|
|
||||||
successCallback(entry);
|
|
||||||
};
|
|
||||||
|
|
||||||
var fail = function(e) {
|
|
||||||
var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
|
|
||||||
errorCallback(error);
|
|
||||||
};
|
|
||||||
|
|
||||||
exec(win, errorCallback, 'FileTransfer', 'download', [source, target]);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = FileTransfer;
|
|
||||||
Reference in New Issue
Block a user