简体   繁体   English

将本地img转换为Base64字符串

[英]Transform local img into Base64 string

I have an img in my project (/Content/Img/myPic.png) and i need to transform it into base 64 and save it in a string variable. 我的项目(/Content/Img/myPic.png)中有一个img,我需要将其转换为base 64并将其保存在字符串变量中。

Something like: 就像是:

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

I don't know how to access my file, and what to use to transform it. 我不知道如何访问我的文件,以及如何使用它进行转换。 Any idea? 任何想法?

Try - angular-file-to-base64-directive , it takes a input file and preduce a base64 . Try- angular-file-to-base64指令 ,它获取input文件并生成base64

Ouput example : Ouput示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM