log file size on file reading fail

This commit is contained in:
Abhinav 2022-05-19 13:01:55 +05:30
parent d207399ddb
commit 94e8e501f2

View file

@ -1,13 +1,27 @@
import { ElectronFile } from 'types/upload'; import { ElectronFile } from 'types/upload';
import { convertBytesToHumanReadable } from 'utils/billing';
export async function getUint8ArrayView( export async function getUint8ArrayView(
reader: FileReader, reader: FileReader,
file: Blob file: Blob
): Promise<Uint8Array> { ): Promise<Uint8Array> {
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
reader.onabort = () => reject(Error('file reading was aborted')); reader.onabort = () =>
reject(
Error(
`file reading was aborted, file size= ${convertBytesToHumanReadable(
file.size
)}`
)
);
reader.onerror = () => reader.onerror = () =>
reject(Error('file reading has failed - ' + reader.error)); reject(
Error(
`file reading has failed, file size= ${convertBytesToHumanReadable(
file.size
)} , reason= ${reader.error}`
)
);
reader.onload = () => { reader.onload = () => {
// Do whatever you want with the file contents // Do whatever you want with the file contents
const result = const result =