Skip to content

Commit 9883258

Browse files
Merge pull request #1 from alekop/master
Update file chooser plugin to be more consistent across platforms:
2 parents c447ec9 + 38754c2 commit 9883258

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ cordova plugin add cordova-plugin-simple-file-chooser
1919

2020
```js
2121
/**
22-
* Displays native prompt for user to select a file.
22+
* Displays native prompt for user to select one or more files.
2323
*
2424
* @param accept Optional MIME type filter (e.g. 'image/gif,video/*').
2525
*
26-
* @returns Promise containing selected file's information,
26+
* @returns Promise containing selected files' information,
2727
* MIME type, display name, and original URI.
2828
*
2929
* If user cancels, promise will be resolved as undefined.
3030
* If error occurs, promise will be rejected.
3131
*/
32-
chooser.getFile(accept?: string) : Promise<undefined|{
32+
chooser.getFiles(accept?: string) : Promise<undefined|{
3333
mediaType: string;
3434
name: string;
3535
uri: string;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-simple-file-chooser",
3-
"version": "2.2.1",
3+
"version": "3.0.0",
44
"description": "Cordova file chooser plugin",
55
"main": "index.js",
66
"repository": {
@@ -30,4 +30,4 @@
3030
"scripts": {
3131
"test": "echo \"Error: no test specified\" && exit 1"
3232
}
33-
}
33+
}

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns="http://www.phonegap.com/ns/plugins/1.0"
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
id="cordova-plugin-simple-file-chooser"
6-
version="2.2.1"
6+
version="3.0.0"
77
>
88
<name>Chooser</name>
99
<author>Cyph, Inc.</author>

src/android/Chooser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.json.JSONObject;
2424

2525
public class Chooser extends CordovaPlugin {
26-
private static final String ACTION_OPEN = "getFile";
26+
private static final String ACTION_OPEN = "getFiles";
2727
private static final int PICK_FILE_REQUEST = 1;
2828
private static final String TAG = "Chooser";
2929

@@ -95,7 +95,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
9595
this.callback.error("File URI was null.");
9696
}
9797
} else if (resultCode == Activity.RESULT_CANCELED) {
98-
this.callback.error("No File selected.");
98+
this.callback.error("RESULT_CANCELED");
9999
} else {
100100
this.callback.error(resultCode);
101101
}

src/ios/Chooser.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UIKit
22
import MobileCoreServices
33
import Foundation
4-
4+
import Cordova
55

66
@objc(Chooser)
77
class Chooser : CDVPlugin {
@@ -46,12 +46,12 @@ class Chooser : CDVPlugin {
4646
}
4747

4848
do {
49-
let result = [
49+
let result = [[
5050
"data": data.base64EncodedString(),
5151
"mediaType": self.detectMimeType(newURL),
5252
"name": newURL.lastPathComponent,
5353
"uri": newURL.absoluteString
54-
]
54+
]]
5555

5656
if let message = try String(
5757
data: JSONSerialization.data(
@@ -80,8 +80,8 @@ class Chooser : CDVPlugin {
8080
url.stopAccessingSecurityScopedResource()
8181
}
8282

83-
@objc(getFile:)
84-
func getFile (command: CDVInvokedUrlCommand) {
83+
@objc(getFiles:)
84+
func getFiles(command: CDVInvokedUrlCommand) {
8585
self.commandCallback = command.callbackId
8686

8787
let accept = command.arguments.first as! String
@@ -163,6 +163,6 @@ extension Chooser : UIDocumentPickerDelegate {
163163
}
164164

165165
func documentPickerWasCancelled (_ controller: UIDocumentPickerViewController) {
166-
self.send("RESULT_CANCELED")
166+
self.sendError("RESULT_CANCELED")
167167
}
168-
}
168+
}

www/chooser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
getFile: function (accept, successCallback, failureCallback) {
2+
getFiles: function (accept, successCallback, failureCallback) {
33
var result = new Promise(function (resolve, reject) {
44
cordova.exec(
55
function (json) {
@@ -12,7 +12,7 @@ module.exports = {
1212
},
1313
reject,
1414
'Chooser',
15-
'getFile',
15+
'getFiles',
1616
[(typeof accept === 'string' ? accept.replace(/\s/g, '') : undefined) || '*/*']
1717
);
1818
});

0 commit comments

Comments
 (0)