使用其 base64 了解文件或图像的大小

Know the size of a file or image, using its base64

我有一个 ionic 应用程序可以使用插件上传图像和 pdf,其中 returns 除了文件大小之外我需要的所有信息,这个 returns 文件的 base64 但我需要验证它不大于 3mb

this.chooser.getFile()
.then((file) => {
  console.log(file.dataURI)
});

这个returns文件的base64,但是我怎么知道文件的大小来验证它不大于3mb?

这将为您提供尺码

const base64str =  base64Data.split('base64,')[1];
const decoded = atob(base64str);
const size = decoded.length