mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-28 10:53:40 +03:00
Add file utility module.
This commit is contained in:
parent
617ee37ec7
commit
598fda9dfc
1 changed files with 37 additions and 0 deletions
37
assets/js/utils/file.js
Normal file
37
assets/js/utils/file.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Online Appointment Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) Alex Tselegidis
|
||||
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link https://easyappointments.org
|
||||
* @since v1.5.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* File utility.
|
||||
*
|
||||
* This module implements the functionality of files.
|
||||
*/
|
||||
window.App.Utils.File = (function () {
|
||||
/**
|
||||
* Convert a file to a base 64 string.
|
||||
*
|
||||
* @param {File} file
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
function toBase64(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = () => resolve(reader.result);
|
||||
reader.onerror = (error) => reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
toBase64
|
||||
};
|
||||
})();
|
Loading…
Reference in a new issue