2016-09-27 28 views
0

我在我的項目(/Content/Img/myPic.png)中有一個img,我需要將其轉換爲基本64並將其保存在字符串變量中。將本地img轉換成Base64字符串

喜歡的東西:

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

我不知道如何訪問我的文件,並利用改造它是什麼。 有什麼想法?

+0

在現代瀏覽器中,檢查出https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/btoa – Carl

+0

http://stackoverflow.com/questions/6150289/how-to-convert-image-into-base64-string-javascript-answer-20285053好像是你在 – Carl

+0

之後好,但是我怎樣才能訪問這個文件給window.btoa( )? – Lempkin

回答

0

嘗試 - angular-file-to-base64-directive,它需要一個input文件並引發base64

輸出繼電器例如:

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