ngSrc and base64 image

2,701 views
Skip to first unread message

Mark Flynn

unread,
Dec 12, 2013, 1:15:30 PM12/12/13
to ang...@googlegroups.com
Hi,

I'm trying to output an image that is sent in base64 format. The image came from an exrternal service and I cannot modify.

 The problem is that this seems a format that angular cannot handle very well. I've checked with php and the string is correct, but I cannot understand why angular cannot display correctly the image.

I've tried with this fiddle: http://jsbin.com/AYIQUhi/2/edit 

Could you help me please?


Daniel Tabuenca

unread,
Dec 12, 2013, 2:36:45 PM12/12/13
to ang...@googlegroups.com
I don't think there is anything wrong with angular. Angular is putting into the html exactly what you are asking it to, but the base64 data in that string looks flawed, it contains dashes "-" which are not a valid base64 encoding. Also, out of curiosity, why do you use underscores in your base64 and then convert them to forward slashes? Why not just have "/" in the string in the first place?

Mark Flynn

unread,
Dec 12, 2013, 3:00:46 PM12/12/13
to ang...@googlegroups.com
As I said in the first post the image came from an exrternal service and I cannot modify it. However what seems strange is that I've tested this string with coldfusion "ImageReadBase64" and it works...

Daniel Tabuenca

unread,
Dec 12, 2013, 5:13:15 PM12/12/13
to ang...@googlegroups.com
You can try removing the dashes. The same way you replace the underscores. I think it makes it work.

Daniel Tabuenca

unread,
Dec 12, 2013, 5:16:17 PM12/12/13
to ang...@googlegroups.com
Actually I think "-" should be replaced with "+'

Daniel Tabuenca

unread,
Dec 12, 2013, 5:18:39 PM12/12/13
to ang...@googlegroups.com
I guess there's a "WEB-Safe" base64 encoding:

https://code.google.com/p/stringencoders/wiki/WebSafeBase64

Switching ("_" -> "/" )  ("-" -> "+") ("*" -> "=") Should do the trick according to that link (but it is not a standard).

Mark Flynn

unread,
Dec 12, 2013, 11:07:05 PM12/12/13
to ang...@googlegroups.com
Thanks!!!

Mani Amuthan

unread,
Feb 22, 2014, 7:37:24 AM2/22/14
to ang...@googlegroups.com
Mark,
Where you able to resolve this issue, coz i'm also facing the same issue and i couldnt find the right solution... can u share me if you have any...


On Thursday, 12 December 2013 23:07:05 UTC-5, Mark Flynn wrote:
Thanks!!!

buyi wen

unread,
Sep 22, 2015, 4:16:48 AM9/22/15
to AngularJS
you can try this free online service to convert image to base64 string online.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages