cordova-plugin-chooser
Advanced tools
Comparing version 1.2.7 to 1.3.0
{ | ||
"name": "cordova-plugin-chooser", | ||
"version": "1.2.7", | ||
"version": "1.3.0", | ||
"description": "Cordova file chooser plugin", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -37,2 +37,19 @@ # Chooser | ||
}> | ||
/** | ||
* Displays native prompt for user to select a file. | ||
* | ||
* @param accept Optional MIME type filter (e.g. 'image/gif,video/*'). | ||
* | ||
* @returns Promise containing selected file's MIME type, display name, | ||
* and original URI. | ||
* | ||
* If user cancels, promise will be resolved as undefined. | ||
* If error occurs, promise will be rejected. | ||
*/ | ||
chooser.getFileMetadata(accept?: string) : Promise<undefined|{ | ||
mediaType: string; | ||
name: string; | ||
uri: string; | ||
}> | ||
@@ -39,0 +56,0 @@ ## Example Usage |
/** @see sodiumutil */ | ||
function from_base64 (sBase64, nBlocksSize) { | ||
function _b64ToUint6 (nChr) { | ||
function from_base64 (sBase64, nBlocksSize) { | ||
function _b64ToUint6 (nChr) { | ||
return nChr > 64 && nChr < 91 ? | ||
@@ -45,20 +45,26 @@ nChr - 65 : | ||
module.exports = { | ||
getFile: function (accept, successCallback, failureCallback) { | ||
if (typeof accept === 'function') { | ||
failureCallback = successCallback; | ||
successCallback = accept; | ||
accept = undefined; | ||
} | ||
function getFileInternal ( | ||
accept, | ||
includeData, | ||
successCallback, | ||
failureCallback | ||
) { | ||
if (typeof accept === 'function') { | ||
failureCallback = successCallback; | ||
successCallback = accept; | ||
accept = undefined; | ||
} | ||
var result = new Promise(function (resolve, reject) { | ||
cordova.exec( | ||
function (json) { | ||
if (json === 'RESULT_CANCELED') { | ||
resolve(); | ||
return; | ||
} | ||
var result = new Promise(function (resolve, reject) { | ||
cordova.exec( | ||
function (json) { | ||
if (json === 'RESULT_CANCELED') { | ||
resolve(); | ||
return; | ||
} | ||
try { | ||
var o = JSON.parse(json); | ||
try { | ||
var o = JSON.parse(json); | ||
if (includeData) { | ||
var base64Data = o.data.replace( | ||
@@ -72,29 +78,42 @@ /[^A-Za-z0-9\+\/]/g, | ||
'data:' + o.mediaType + ';base64,' + base64Data; | ||
resolve(o); | ||
} | ||
catch (err) { | ||
reject(err); | ||
else { | ||
delete o.data; | ||
} | ||
}, | ||
reject, | ||
'Chooser', | ||
'getFile', | ||
[ | ||
(typeof accept === 'string' ? | ||
accept.toLowerCase().replace(/\s/g, '') : | ||
undefined) || '*/*' | ||
] | ||
); | ||
}); | ||
if (typeof successCallback === 'function') { | ||
result.then(successCallback); | ||
} | ||
if (typeof failureCallback === 'function') { | ||
result.catch(failureCallback); | ||
} | ||
resolve(o); | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
}, | ||
reject, | ||
'Chooser', | ||
'getFile', | ||
[ | ||
(typeof accept === 'string' ? | ||
accept.toLowerCase().replace(/\s/g, '') : | ||
undefined) || '*/*', | ||
includeData | ||
] | ||
); | ||
}); | ||
return result; | ||
if (typeof successCallback === 'function') { | ||
result.then(successCallback); | ||
} | ||
if (typeof failureCallback === 'function') { | ||
result.catch(failureCallback); | ||
} | ||
return result; | ||
} | ||
module.exports = { | ||
getFile: function (accept, successCallback, failureCallback) { | ||
return getFileInternal(accept, true, successCallback, failureCallback); | ||
}, | ||
getFileMetadata: function (accept, successCallback, failureCallback) { | ||
return getFileInternal(accept, false, successCallback, failureCallback); | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15008
233
81