mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Some checks failed
Runs E2E API Tests / build (20.x) (push) Has been cancelled
Runs E2E API Tests / build (22.6) (push) Has been cancelled
Lint & build / lint_and_build (20.x) (push) Has been cancelled
Lint & build / lint_and_build (22.6) (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
* profile_image_uploader * feat: upload_link_value_change_and_refresh * Migrate to v2 * avatar editor v2 * added back missing pieces * fixed dependencies * fixed tests * fixed component structure --------- Co-authored-by: Zai Shi <zaishi00@outlook.com>
14 lines
515 B
TypeScript
14 lines
515 B
TypeScript
export function fileToBase64(file: File): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
const reader = new FileReader();
|
|
reader.readAsDataURL(file);
|
|
reader.onload = () => resolve(reader.result as string);
|
|
reader.onerror = error => reject(error);
|
|
});
|
|
}
|
|
|
|
export function validateBase64Image(base64: string): boolean {
|
|
const base64ImageRegex = /^data:image\/(png|jpg|jpeg|gif|bmp|webp);base64,[A-Za-z0-9+/]+={0,2}$|^[A-Za-z0-9+/]+={0,2}$/;
|
|
return base64ImageRegex.test(base64);
|
|
}
|