将本地img转换为Base64字符串

Transform local img into Base64 string

本文关键字:Base64 字符串 转换 img      更新时间:2023-09-26

我在我的项目(/Content/img/myPic.png)中有一个img,我需要将其转换为64进制并保存在字符串变量中。

类似:

let myFile = File("/Content/Img/myPic.png");
let fileBase64 = Base64Transformer(myFile);

我不知道如何访问我的文件,以及使用什么来转换它。任何想法?

Try - angular-file-to-base64指令,它取一个input文件,生成一个base64文件。

输出示例:

{
    "filesize": 54836, /* bytes */
    "filetype": "image/jpeg",
    "filename": "profile.jpg",
    "base64":   "/9j/4AAQSkZJRgABAgAAAQABAAD//gAEKgD/4gIctcwIQA..."
  }