2016-08-08 2 views
0

내 파일 이름을 db에 저장하고 파일을 파일 서버에 저장하십시오. 그래서 나는 그 파일을 액세스하여 이름을 얻고 <img src='http://localhost/upload/abc.jpg'/> 여기서 abc는 파일 이름입니다. 그러나 어떻게 base64를 얻을 수 있습니까? 실제 파일을 가져 와서 어딘가에 전달해야하기 때문입니다. 이미지가 동일한 도메인에있는 경우파일 이름으로 base64를 가져와

+2

을 그것을 할 수 있습니다. 당신은 실제로 무엇을하려고합니까? – Archer

+0

http://stackoverflow.com/questions/19124701/get-image-using-jquery-ajax-and-decode-it-to-base64/25371174#25371174 – gaetanoM

답변

0

, 당신은 ... 캔버스와 서버 측 코드가 아닌 클라이언트 측 될 것

function getBase64Image(img) { 
    var canvas = document.createElement("canvas"); 
    canvas.width = img.width; 
    canvas.height = img.height; 
    var ctx = canvas.getContext("2d"); 
    ctx.drawImage(img, 0, 0); 
    return canvas.toDataURL("image/png"); 
} 

// if the image is on the dom use this 
var img = document.getElementById('img'); 
alert(getBase64Image(img)); 

// if the image isn't on the dom do this.. 
var img = new Image(); 
img.onload = function(){ 
    alert(getBase64Image(img)); 
} 
img.src= "http://my/image/url.png"; 
+0

고맙습니다. –

관련 문제