Skip to content

Commit

Permalink
feat: Added function WPP.util.blobToBase64
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jan 8, 2022
1 parent 1bbe448 commit fc06eef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/util/blobToBase64.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
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);
});
}
2 changes: 2 additions & 0 deletions src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

export * from './blobToBase64';
export * from './convertToFile';
export * from './createWid';
export * from './errors';
export * from './types';

0 comments on commit fc06eef

Please sign in to comment.