8

I'm using openfb-angular (Facebook API library) to get me/picture.
The return data is "url" contains Base64 data here is the facebook documentation.

Here is my code:

JS

OpenFB.get('/me/picture', {format: 'json'}).success(function (imgData)
        {
            $scope.main.user.imageData = imgData;
        });

HTML

 <img ng-src="data:image/jpg;base64,{{main.user.imageData}}">

It's not working and I get an empty img tag.

Where is my mistake?

4
  • please paste any sample of imageData. did you checked the format of image you are getting back? is it jpg? If possible please post code in Plunker. Like i have a image shown here plnkr.co/edit/m24ZcYuttw6IuCBh02rQ?p=preview Commented Dec 24, 2014 at 13:21
  • 1
    have you tried to use src only instead of ng-src? Commented Dec 24, 2014 at 14:10
  • Is it should be image/jpeg instead of image/jpg? Commented Jan 1, 2015 at 14:21
  • hi @cheziHoyzer, i´m facing this issue right now... have you solved the problem with the image in base64? thx Commented Jun 19, 2015 at 8:31

4 Answers 4

15

Use ng-source directive like this:

<img ng-src="{{'data:image/png;base64,'+main.user.imageData}}" >

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

6

Use data-ng-src directive like this <img data-ng-src="{{data.image_url}}">.

In your controller set base64 string as this: $scope.data.image_url=<your base64 image source>

Hope this helps!

Comments

1
<img data-ng-src="data:image/png;base64,{{main.user.imageData}}"/>

Hope this helps.

Comments

-1

In Angular 7, this would be:

<img [src]="'data:image/png;base64,' + main.user.imageData" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.