fix: do't transform big file to base64

pull/24/head
fantasticit 2022-03-31 23:05:50 +08:00
parent 2b224b1246
commit 9fe447f88b
1 changed files with 6 additions and 1 deletions

View File

@ -1,7 +1,12 @@
import { string } from 'lib0';
import { HttpClient } from './HttpClient'; import { HttpClient } from './HttpClient';
const ONE_MB = 1 * 1024 * 1024;
export const readFileAsDataURL = (file): Promise<string | ArrayBuffer> => { export const readFileAsDataURL = (file): Promise<string | ArrayBuffer> => {
if (file.size > ONE_MB) {
return Promise.reject(new Error('文件过大,请实现文件上传到存储服务!'));
}
return new Promise((resolve) => { return new Promise((resolve) => {
const reader = new FileReader(); const reader = new FileReader();
reader.addEventListener('load', (e) => resolve(e.target.result), { once: true }); reader.addEventListener('load', (e) => resolve(e.target.result), { once: true });