From 9fe447f88b3260140915bb1bd1fb6d9c44cf208f Mon Sep 17 00:00:00 2001 From: fantasticit Date: Thu, 31 Mar 2022 23:05:50 +0800 Subject: [PATCH] fix: do't transform big file to base64 --- packages/client/src/services/file.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/client/src/services/file.ts b/packages/client/src/services/file.ts index 26b9a25..028a4a7 100644 --- a/packages/client/src/services/file.ts +++ b/packages/client/src/services/file.ts @@ -1,7 +1,12 @@ -import { string } from 'lib0'; import { HttpClient } from './HttpClient'; +const ONE_MB = 1 * 1024 * 1024; + export const readFileAsDataURL = (file): Promise => { + if (file.size > ONE_MB) { + return Promise.reject(new Error('文件过大,请实现文件上传到存储服务!')); + } + return new Promise((resolve) => { const reader = new FileReader(); reader.addEventListener('load', (e) => resolve(e.target.result), { once: true });