Filesize limit for logoupload (#2522)
* add readable byts helper function * adjust wording for logo upload * limit file size to 2 MB * remove log Co-authored-by: Gabe Kangas <gabek@real-ity.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import { RcFile } from 'antd/lib/upload';
|
||||
|
||||
export const MAX_IMAGE_FILESIZE = 2097152;
|
||||
export const ACCEPTED_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/gif'];
|
||||
|
||||
export function getBase64(img: File | Blob, callback: (imageUrl: string | ArrayBuffer) => void) {
|
||||
@@ -5,3 +8,11 @@ export function getBase64(img: File | Blob, callback: (imageUrl: string | ArrayB
|
||||
reader.addEventListener('load', () => callback(reader.result));
|
||||
reader.readAsDataURL(img);
|
||||
}
|
||||
|
||||
export function readableBytes(bytes: number): string {
|
||||
const index = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
const SIZE_UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
const size = Number((bytes / Math.pow(1024, index)).toFixed(2)) * 1;
|
||||
|
||||
return `${size} ${SIZE_UNITS[index]}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user