我的圖片上傳與HTML5的FileReader的幫助是這樣的:代表圖像
$scope.add = function(){
var f = document.getElementById('file').files[0],
r = new FileReader();
r.onloadend = function(e){
var data = e.target.result;
console.log(data);
$http.post(myUrl,{
data: e.target.result,
withCredentials: true,
}).success(function (dat) {
$scope.image = dat; // If you want to render the image after successfully uploading in your db
});
}
r.readAsBinaryString(f)
}
HTML代碼:
<input type="file" id="file" name="file"/>
<button ng-click="add()">Add</button>
但是,當我得到我的照片回來我不知道如何表達它。它不是基於64位的字符串,從e.target.result
讀取,我甚至不知道FileReader
使用什麼。你能幫我代表這些數據嗎?
什麼,當你將鼠標懸停在您的「DAT顯示「在你的成功對象? –