"use strict"; exports.id = 8345; exports.ids = [8345]; exports.modules = { /***/ 8345: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "Z": () => (/* binding */ inputFileToBase64) /* harmony export */ }); // @ts-check /** * @typedef {{ * fileBase64: string | null, * fileBase64Full: string | null, * fileName: string | null, * fileSize: number | null, * fileType: string | null, * }} FunctionReturn */ /** * Upload a file * ============================================================================== * @async * * @param {{ * inputFile: File, * }} params - Single object passed * * @description This function takes in a *SINGLE* input file from a HTML file input element. * HTML file input elements usually return an array of input objects, so be sure to select the target * file from the array. * * @returns { Promise } - Return Object */ async function inputFileToBase64({ inputFile }) { /** * == Initialize * * @description Initialize */ // const allowedTypesRegex = /image\/*|\/pdf/; // if (!inputFile?.type?.match(allowedTypesRegex)) { // window.alert(`We currently don't support ${inputFile.type} file types. Support is coming soon. For now we support only images and PDFs.`); // return { // fileBase64: null, // fileBase64Full: null, // fileName: inputFile.name, // fileSize: null, // fileType: null, // }; // } try { /** * == Process File */ let fileName = inputFile.name.replace(/\..*/, ""); /** Add source to new file **/ const fileData = await new Promise((resolve, reject)=>{ var reader = new FileReader(); reader.readAsDataURL(inputFile); reader.onload = function() { resolve(reader.result); }; reader.onerror = function(/** @type {any} */ error) { console.log("Error: ", error.message); }; }); return { fileBase64: fileData.replace(/.*?base64,/, ""), fileBase64Full: fileData, fileName: fileName, fileSize: inputFile.size, fileType: inputFile.type }; } catch (/** @type {any} */ error) { console.log("Image Processing Error! =>", error.message); return { fileBase64: null, fileBase64Full: null, fileName: inputFile.name, fileSize: null, fileType: null }; } } //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /***/ }) }; ;