我每次通過Facebook登錄時都會抓取用戶的Facebook個人資料圖片。我想從URL中將圖像轉換爲64位。這樣做的最佳方式是什麼,同時確保用戶仍然可以在視圖(home.view)中看到他們的個人資料圖片?目前,我直接參考了URL。將從URL提取的圖像轉換爲base64
這是到目前爲止我的代碼:
facebook.service.js
function FacebookService($http, config) {
this.getUserPicture = function(userId, token) {
return $http({
method: 'GET',
url: 'https://graph.facebook.com/' + userId + '/picture?type=large&redirect=false'
})
}
}
home.controller.js
function HomeController($scope, $cordovaNativeStorage, FacebookService, $ionicLoading) {
if (window.cordova) {
// Get Facebook access token
$cordovaNativeStorage.getItem("facebookAccessToken").then(function(value) {
$scope.facebookAccessToken = value
// Get Facebook user picture (currently stored as a URL, would want to store it as a base 64 string which can be displayed as an image
FacebookService.getUserPicture($scope.facebookUserData.id).then(function(dataResponse) {
$scope.facebookUserPicture = dataResponse.data;
// Save Facebook user picture
$cordovaNativeStorage.setItem("facebookUserPicture", $scope.facebookUserPicture).then(function() {}, function(error) {
console.error("Unable to cache user data: " + result);
$ionicLoading.show({
template: 'Unable to cache user data',
duration: 1500
})
});
}, function(error) {
console.log(error.data.error.message)
})
}, function(error) {
console.log(error.data.error.message)
})
}
};
home.view.js
<img class="icon icon-home img-circle" ng-src="{{ facebookUserPicture.data.url }}">
基地64是有的,但爲什麼你想轉換回正常的鏈接? –
你要在應用程序端還是Web視圖中將其轉換回來? –
哦,對不起,我認爲有一個誤解,我的意思是將其轉換爲可以不被URL查看的圖像,因此,可以有效地將字符串作爲照片在屏幕上顯示給用戶。抱歉的混淆。 – methuselah