1

I have a C# method (that is an ActiveX component that runs on the client) that returns a photo. On C# side I have two properties:

public byte[] Photo { get; set; }
public string PhotoString { get; set; }

The string version is gotten by simple conversion with System.Convert.ToBase64String().

Now I need a way to show that photo using javascript. I tried using the code from this answer: How to display binary data as image - extjs 4

with

$("#imgUserImage").attr("src", 'data:image/jpeg;base64,' + hexToBase64(data.PhotoString));

But that didn't work. Also if I copy my string to the fiddle in that answer it's not working so I'm assuming the problem is in the string.

Any other suggestions?

Community
  • 1
  • 1
Fedor Hajdu
  • 4,657
  • 3
  • 32
  • 50

1 Answers1

1

If it's already encoded properly, you don't need to call hexToBase64().

$("#imgUserImage").attr("src", 'data:image/jpeg;base64,'+data.PhotoString);

Demo in jsFiddle

Benoit Blanchon
  • 13,364
  • 4
  • 73
  • 81