Skip to content

Commit

Permalink
Merge pull request #1 from alekop/master
Browse files Browse the repository at this point in the history
Update file chooser plugin to be more consistent across platforms:
  • Loading branch information
harshzalavadiya authored Nov 16, 2021
2 parents c447ec9 + 38754c2 commit 9883258
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ cordova plugin add cordova-plugin-simple-file-chooser

```js
/**
* Displays native prompt for user to select a file.
* Displays native prompt for user to select one or more files.
*
* @param accept Optional MIME type filter (e.g. 'image/gif,video/*').
*
* @returns Promise containing selected file's information,
* @returns Promise containing selected files' information,
* MIME type, display name, and original URI.
*
* If user cancels, promise will be resolved as undefined.
* If error occurs, promise will be rejected.
*/
chooser.getFile(accept?: string) : Promise<undefined|{
chooser.getFiles(accept?: string) : Promise<undefined|{
mediaType: string;
name: string;
uri: string;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-simple-file-chooser",
"version": "2.2.1",
"version": "3.0.0",
"description": "Cordova file chooser plugin",
"main": "index.js",
"repository": {
Expand Down Expand Up @@ -30,4 +30,4 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
}
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-simple-file-chooser"
version="2.2.1"
version="3.0.0"
>
<name>Chooser</name>
<author>Cyph, Inc.</author>
Expand Down
4 changes: 2 additions & 2 deletions src/android/Chooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.json.JSONObject;

public class Chooser extends CordovaPlugin {
private static final String ACTION_OPEN = "getFile";
private static final String ACTION_OPEN = "getFiles";
private static final int PICK_FILE_REQUEST = 1;
private static final String TAG = "Chooser";

Expand Down Expand Up @@ -95,7 +95,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
this.callback.error("File URI was null.");
}
} else if (resultCode == Activity.RESULT_CANCELED) {
this.callback.error("No File selected.");
this.callback.error("RESULT_CANCELED");
} else {
this.callback.error(resultCode);
}
Expand Down
14 changes: 7 additions & 7 deletions src/ios/Chooser.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import MobileCoreServices
import Foundation

import Cordova

@objc(Chooser)
class Chooser : CDVPlugin {
Expand Down Expand Up @@ -46,12 +46,12 @@ class Chooser : CDVPlugin {
}

do {
let result = [
let result = [[
"data": data.base64EncodedString(),
"mediaType": self.detectMimeType(newURL),
"name": newURL.lastPathComponent,
"uri": newURL.absoluteString
]
]]

if let message = try String(
data: JSONSerialization.data(
Expand Down Expand Up @@ -80,8 +80,8 @@ class Chooser : CDVPlugin {
url.stopAccessingSecurityScopedResource()
}

@objc(getFile:)
func getFile (command: CDVInvokedUrlCommand) {
@objc(getFiles:)
func getFiles(command: CDVInvokedUrlCommand) {
self.commandCallback = command.callbackId

let accept = command.arguments.first as! String
Expand Down Expand Up @@ -163,6 +163,6 @@ extension Chooser : UIDocumentPickerDelegate {
}

func documentPickerWasCancelled (_ controller: UIDocumentPickerViewController) {
self.send("RESULT_CANCELED")
self.sendError("RESULT_CANCELED")
}
}
}
4 changes: 2 additions & 2 deletions www/chooser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
getFile: function (accept, successCallback, failureCallback) {
getFiles: function (accept, successCallback, failureCallback) {
var result = new Promise(function (resolve, reject) {
cordova.exec(
function (json) {
Expand All @@ -12,7 +12,7 @@ module.exports = {
},
reject,
'Chooser',
'getFile',
'getFiles',
[(typeof accept === 'string' ? accept.replace(/\s/g, '') : undefined) || '*/*']
);
});
Expand Down

0 comments on commit 9883258

Please sign in to comment.