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?

1 Answer 1

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

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

2 Comments

wow that simple!? Thanks it worked. I can't accept your answer for 6 more minutes but I'll do it.
Thanks ! FYI, I encoded using this site motobit.com/util/base64-decoder-encoder.asp

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.