未启动FileReader onload回调

时间:2019-03-07 16:19:22

标签: javascript angular html5

onload回调从未触发。我在做什么错了?

export function fileReadAsBase64(file: File): Promise<string> {
    if (!file)
        return Promise.resolve("");
    return new Promise<string>((resolve, reject) => {
        const reader = new FileReader();
        reader.onload = (e: any) => {
            console.log(e);
            resolve(reader.result.toString());
        };
        reader.readAsDataURL(file);
    });
}

0 个答案:

没有答案