From fc06eef900cc423709fb6a275e004f630ca352c3 Mon Sep 17 00:00:00 2001 From: Edgard Date: Sat, 8 Jan 2022 19:14:41 -0300 Subject: [PATCH] feat: Added function WPP.util.blobToBase64 --- src/util/blobToBase64.ts | 27 +++++++++++++++++++++++++++ src/util/index.ts | 2 ++ 2 files changed, 29 insertions(+) create mode 100644 src/util/blobToBase64.ts diff --git a/src/util/blobToBase64.ts b/src/util/blobToBase64.ts new file mode 100644 index 0000000000..c1974195da --- /dev/null +++ b/src/util/blobToBase64.ts @@ -0,0 +1,27 @@ +/*! + * Copyright 2021 WPPConnect Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function blobToBase64(blob: Blob): Promise { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onloadend = function () { + resolve(reader.result as string); + }; + reader.onabort = reject; + reader.onerror = reject; + reader.readAsDataURL(blob); + }); +} diff --git a/src/util/index.ts b/src/util/index.ts index bcdf9a7f6d..9dcbed829b 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +export * from './blobToBase64'; +export * from './convertToFile'; export * from './createWid'; export * from './errors'; export * from './types';